https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85461
Bug ID: 85461 Summary: A simple recursive TMP static const initializer defeats gcc Product: gcc Version: unknown 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 test case is as follow: template<unsigned int v> class bitWidthHolding { public: /** width is the number of bits occupied by the template parameter v */ static const unsigned int width = (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::width + 1); }; clang++ compiles the code, but gcc produces errors: ../1Testprogramtoillustratetheproblembuiltwithclang-ctestit.cpp: In instantiation of ‘const unsigned int bitWidthHolding<0>::width’: ../1Testprogramtoillustratetheproblembuiltwithclang-ctestit.cpp:7:73: recursively required from ‘const unsigned int bitWidthHolding<127>::width’ ../1Testprogramtoillustratetheproblembuiltwithclang-ctestit.cpp:7:73: required from ‘const unsigned int bitWidthHolding<255>::width’ ../1Testprogramtoillustratetheproblembuiltwithclang-ctestit.cpp:10:46: required from here ../1Testprogramtoillustratetheproblembuiltwithclang-ctestit.cpp:7:73: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) unsigned int width = (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::width + 1); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ A bug report from clang (https://bugs.llvm.org/show_bug.cgi?id=9999) explains some details.