Clang accepts this code, but GCC rejects it:
class Foo {
 public:
  static constexpr double kVal = 0.25f;
};
const double Foo::kVal;
(Using clang 3.0 and g++ 4.6.3)
~$ clang++ foo.cc -std=c++11 -c 
[ok]
~$ g++ foo.cc -std=c++0x -c 
foo.cc:6:19: error: redeclaration ‘Foo::kVal’ differs in ‘constexpr’
foo.cc:3:34: error: from previous declaration ‘Foo::kVal’
foo.cc:6:19: error: declaration of ‘constexpr const double Foo::kVal’ outside of class is not definition [-fpermissive]
Which interpretation is correct?
clang is correct. It looks like somebody on the gcc team misread or misimplemented:
7.1.5/1:
If any declaration of a function or function template has
constexprspecifier, then all its declarations shall contain theconstexprspecifier.
Foo::kVal is obviously not a function or function template.  I don't see anything else in the Standard requiring use of constexpr to be consistent from one declaration to the next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With