https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86503
--- Comment #3 from zhonghao at pku dot org.cn --- (In reply to Richard Biener from comment #1) > You run out of memory or stack. Try ulimit -s unlimited I tried ulimit -s unlimited. This time, the error messages are as follows: g++ -ftemplate-depth=1000000 test.cpp test.cpp: In substitution of 'template<class F, int n> __typeof__ (ft<F, (n - 1)>(F(), 0)) ft(F, typename enable_if<(n != 0), int>::type) [with F = main()::a*; int n = -999997]': test.cpp:14:21: recursively required by substitution of 'template<class F, int n> __typeof__ (ft<F, (n - 1)>(F(), 0)) ft(F, typename enable_if<(n != 0), int>::type) [with F = main()::a*; int n = 1]' test.cpp:14:21: required by substitution of 'template<class F, int n> __typeof__ (ft<F, (n - 1)>(F(), 0)) ft(F, typename enable_if<(n != 0), int>::type) [with F = main()::a*; int n = 2]' test.cpp:18:30: required from here test.cpp:14:21: fatal error: template instantiation depth exceeds maximum of 1000000 (use -ftemplate-depth= to increase the maximum) typeof( ft< F, n-1 >( F(), 0 ) ) ~~~~~~~~~~~~~~^~~~~~~~~~~~ compilation terminated.