From Bugzilla Helper: User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22smp i686) g++ fails to detect an illegal attempt to initialize a non-integral static const member of a class inside the class declaration. Reproducible: Always Steps to Reproduce: The following piece of code should generate an error: #include <stdio.h> class A { public: const static int N = 10; // OK const static float EPS = 0.0001; // illegal }; const int A::N; const float A::EPS; int main() { const int *pi = &A::N; printf("%d %d\n", A::N, *pi); const float *pf = &A::EPS; printf("%g %g\n", A::EPS, *pf); return 0; } Actual Results: Currently, g++ (gcc-2.96-69) will accept that piece of code, and produce an executable. Expected Results: g++ should abort compilation with an error. See page 249 of Bjarne Stroustrup, "The C++ Programming Language", Special Edition, 2000.
No, it does detect it, but handles this as an extension to the standard. If you want a warning, simply run g++ with -pedantic, if you want this to be an error, run with -pedantic-errors: g++ -pedantic-errors test.C test.C:6: ISO C++ forbids initialization of member constant `EPS' of non-integral type `const float'