Created attachment 37299 [details] Test C++ file I have an implementation of Y Combinator in C++, which works in GCC 4.9 to 5.1 as well as Clang 3.5 (in C++14 mode). It stops working in GCC 5.2 and 5.3, so I think it is regression. I think GCC is being too eager in template instantiation. As I also tried using the GCC 5.1 C++ header files with GCC 5.2 and got the same errors, I guess it is a C++ front end problem. The test program is supposed to apply the Y combinator to a non-recursive function almost_fac to get a factorial function. It should compile well and output two lines of "120", but now it fails the compilation at the "fix_curry(almost_fac)" line. I tested on Windows and OS X. The Windows error output is: In file included from test_gcc.cpp:1:0: C:/mingw64/x86_64-w64-mingw32/include/c++/functional: In substitution of 'template<class _Functor, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = std::function<std::function<int(int)>(self_ref_func<std::function<int(int)> >)>; <template-parameter-1-2> = <missing>]': C:/mingw64/x86_64-w64-mingw32/include/c++/functional:1981:45: recursively required by substitution of 'template<class _Functor, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = std::function<std::function<int(int)>(self_ref_func<std::function<int(int)> >)>; <template-parameter-1-2> = <missing>]' C:/mingw64/x86_64-w64-mingw32/include/c++/functional:1981:45: required by substitution of 'template<class _Functor, class> std::function<_Res(_ArgTypes ...)>::function(_Functor) [with _Functor = std::function<std::function<int(int)>(self_ref_func<std::function<int(int)> >)>; <template-parameter-1-2> = <missing>]' test_gcc.cpp:47:51: required from 'fix_curry(std::function<std::function<_Rs(_Tp)>(std::function<_Rs(_Tp)>)>)::<lambda(fn_self_ref)>::<lambda(_Tp&&)> [with _Rs = int; _Tp = int]' test_gcc.cpp:45:34: required from 'struct fix_curry(std::function<std::function<_Rs(_Tp)>(std::function<_Rs(_Tp)>)>)::<lambda(fn_self_ref)> [with _Rs = int; _Tp = int; fn_self_ref = self_ref_func<std::function<int(int)> >]::<lambda(int&&)>' test_gcc.cpp:45:21: required from 'fix_curry(std::function<std::function<_Rs(_Tp)>(std::function<_Rs(_Tp)>)>)::<lambda(fn_self_ref)> [with _Rs = int; _Tp = int; fn_self_ref = self_ref_func<std::function<int(int)> >]' test_gcc.cpp:43:10: required from 'struct fix_curry(std::function<std::function<_Rs(_Tp)>(std::function<_Rs(_Tp)>)>) [with _Rs = int; _Tp = int]::<lambda(fn_self_ref)>' test_gcc.cpp:50:5: required from 'std::function<_Rs(_Tp)> fix_curry(std::function<std::function<_Rs(_Tp)>(std::function<_Rs(_Tp)>)>) [with _Rs = int; _Tp = int]' test_gcc.cpp:69:43: required from here C:/mingw64/x86_64-w64-mingw32/include/c++/functional:1981:69: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) using _Invoke = decltype(__callable_functor(std::declval<_Functor&>()) ^ compilation terminated.
This is PR 69005 which I still have a pending patch for, in addition to Jason's front-end change.
Not a 6 regression, it was already fixed on trunk for PR 69005.
Author: redi Date: Tue Jan 12 14:54:33 2016 New Revision: 232273 URL: https://gcc.gnu.org/viewcvs?rev=232273&root=gcc&view=rev Log: Prevent recursive instantiation in std::function PR libstdc++/69005 PR libstdc++/69222 * include/std/functional (function::_Invoke): Remove, use result_of. (function::_Callable): Replace alias template with class template and use partial specialization instead of _NotSelf alias template. (function(_Functor)): Add "not self" constraint so that _Callable is not used while type is incomplete. * testsuite/20_util/function/69222.cc: New. Added: trunk/libstdc++-v3/testsuite/20_util/function/69222.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/std/functional
Author: redi Date: Tue Jan 12 14:55:00 2016 New Revision: 232274 URL: https://gcc.gnu.org/viewcvs?rev=232274&root=gcc&view=rev Log: Prevent recursive instantiation in std::function PR libstdc++/69005 PR libstdc++/69222 * include/std/functional (function::_Invoke): Remove, use result_of. (function::_Callable): Replace alias template with class template and use partial specialization instead of _NotSelf alias template. (function(_Functor)): Add "not self" constraint so that _Callable is not used while type is incomplete. * testsuite/20_util/function/69222.cc: New. Added: branches/gcc-5-branch/libstdc++-v3/testsuite/20_util/function/69222.cc Modified: branches/gcc-5-branch/libstdc++-v3/ChangeLog branches/gcc-5-branch/libstdc++-v3/include/std/functional
Fixed for 5.4