https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67437
Bug ID: 67437 Summary: [5/6 Regression] Template can't use const value of explicitly instantiated instance in a const expression Product: gcc Version: 5.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Bernhard.Rosenkranzer at linaro dot org Target Milestone: --- The following code builds fine with gcc versions up to 4.9 and with any version of clang, but fails with gcc 5.1, 5.2 and trunk: template <int N> struct I0ATerm { static const double value = I0ATerm<N-1>::value * (2.*N-1.) * (2.*N-1.) / (8. * N); }; template <> struct I0ATerm<0> { // 1/sqrt(2*PI); static const double value = 0.398942280401432677939946059934381868475858631164934657665925; }; int main(int argc, char **argv) { I0ATerm<1>::value; } Error message from gcc 5.2: test.cpp: In instantiation of 'const double I0ATerm<1>::value': test.cpp:12:14: required from here test.cpp:3:22: error: the value of 'I0ATerm<0>::value' is not usable in a constant expression static const double value = I0ATerm<N-1>::value * (2.*N-1.) * (2.*N-1.) / (8. * N); ^ test.cpp:8:22: note: 'I0ATerm<0>::value' does not have integral or enumeration type static const double value = 0.398942280401432677939946059934381868475858631164934657665925; ^ (changing "double" to "int" "fixes" it (but of course that loss of precision is not always acceptable). Given the double is a constant expression, I'm not sure this is intended to break.