https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68411

            Bug ID: 68411
           Summary: Error in template instantion, cause recursive template
                    reference.
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msnkipa at mail dot ru
  Target Milestone: ---

This code could not be compiled:
std::exception_ptr safe(std::function<void()>); // Defined somewhere in file
template<typename F, typename... Args>
        auto safe(typename
std::enable_if<std::is_void<std::result_of<F(Args...)>>::value, int*>::type,
                                                                               
        F func, Args... args) -> std::pair<decltype(func(args...)),
std::exception_ptr>
{
        decltype(func(args...)) result{};
        std::exception_ptr exp{ /*safe([&]{ result = func(args...); })*/ };
        return { result, exp };
}
template<typename F, typename... Args, typename = int>
        auto safe(typename
std::enable_if<!std::is_void<std::result_of<F(Args...)>>::value, int*>::type,
                                                                               
                                                                               
                        F func, Args... args) -> std::exception_ptr
{
        return safe([&]{ func(args...); });
}
template<typename F, typename... Args>
                auto safe(F func, Args... args) -> typename
std::conditional<std::is_void<decltype(func(args...))>::value,
                                                                               
        std::exception_ptr, std::pair<decltype(func(args...)),
std::exception_ptr>>::type
{
        return safe(nullptr, func, args...);
}

int main()
{
        safe([&] { std::cout << "Hello" << std::end; });
}

Error is:
C:/mingw-w64/mingw64/x86_64-w64-mingw32/include/c++/type_traits: In
instantiation of 'struct std::is_reference<dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(!
std::is_void<std::result_of<_Functor(_ArgTypes ...)> >::value), int*>::type, F,
Args ...) [with F = dcs::safe(typename std::enable_if<(! ... many such lines
...
C:/mingw-w64/mingw64/x86_64-w64-mingw32/include/c++/type_traits:544:12: fatal
error: template instantiation depth exceeds maximum of 900 (use
-ftemplate-depth= to increase the maximum)
     struct is_reference

PS: clang compile this code without problems.

Reply via email to