https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86503
Bug ID: 86503 Summary: Segmentation fault signal terminated Product: gcc Version: 8.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: zhonghao at pku dot org.cn Target Milestone: --- The code is as follow: template< bool c, class T > struct enable_if { typedef T type; }; template< class T > struct enable_if< true, T > {}; template< class F, int n > void ft( F f, typename enable_if< n == 0, int >::type ) {} template< class F, int n > typeof( ft< F, n-1 >( F(), 0 ) ) ft( F f, typename enable_if< n != 0, int >::type ) {} int main() { ft< struct a*, 2 >( 0, 0 ); } g++ produces the following error message: 3regressiontestusingG++typeof.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 = -897]': 3regressiontestusingG++typeof.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]' 3regressiontestusingG++typeof.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]' 3regressiontestusingG++typeof.cpp:18:30: required from here 3regressiontestusingG++typeof.cpp:14:21: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) typeof( ft< F, n-1 >( F(), 0 ) ) ~~~~~~~~~~~~~~^~~~~~~~~~~~ compilation terminated. So, I change the command line to: g++ -ftemplate-depth=1000000 3regressiontestusingG++typeof.cpp This time, the error message is as follow: g++: internal compiler error: Segmentation fault signal terminated program cc1plus Please submit a full bug report, with preprocessed source if appropriate. See <https://gcc.gnu.org/bugs/> for instructions. Anyway, clang++ accepts the code.