https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90830
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to zhonghao from comment #0) > However, I tried clang and icc, and both compilers accept the code. Is the > bug fully fixed? They only accept it because your code doesn't instantiate the function template. I've explained this to you before. Try instantiating the template template <int I> constexpr int f () { enum E { a = f<0> () }; return 0; } constexpr int i = f<1>(); Now Clang says: 90830.cc:4:16: error: expression is not an integral constant expression enum E { a = f<0> () }; ^~~~~~~ 90830.cc:4:16: note: in instantiation of function template specialization 'f<0>' requested here 90830.cc:7:19: note: in instantiation of function template specialization 'f<1>' requested here constexpr int i = f<1>(); ^ 90830.cc:4:16: note: undefined function 'f<0>' cannot be used in a constant expression enum E { a = f<0> () }; ^ 90830.cc:2:15: note: declared here constexpr int f () ^ 1 error generated. And EDG says: "90830.cc", line 4: error: expression must have a constant value enum E { a = f<0> () }; ^ "90830.cc", line 4: note: this call cannot be evaluated because the target function function "f<I>() [with I=0]" (declared at line 2) is not constexpr or not completely defined yet enum E { a = f<0> () }; ^ detected during instantiation of "int f<I>() [with I=0]" at line 4 "90830.cc", line 7: warning: variable "i" was declared but never referenced constexpr int i = f<1>(); ^ 1 error detected in the compilation of "90830.cc". Apart from that, *obviously* the code is not valid because it would cause infinite recursion. That should be obvious.