[C++14: 7.1.5/1]:
Theconstexpr
specifier shall be applied only to the definition of a variable or variable template, the declaration of a function or function template, or the declaration of a static data member of a literal type (3.9). If any declaration of a function, function template, or variable template has aconstexpr
specifier, then all its declarations shall contain theconstexpr
specifier. [..]
Notice that the second sentence does not mention "a static data member" the way the first sentence does, so there is no requirement in this passage that all declarations (and here I'm considering a defining declaration specifically) of a constexpr
static
data member have the constexpr
specifier.
I can't find a rule elsewhere to mandate this, either.
Why, then, does GCC reject the following program?
#include <chrono>
using namespace std::chrono_literals;
#define DUR 1000ms
struct T
{
static constexpr auto dur_1 = DUR;
};
decltype(T::dur_1) T::dur_1;
// main.cpp:12:23: error: 'constexpr' needed for in-class initialization of static data member 'const std::chrono::duration<long int, std::ratio<1l, 1000l> T::dur_1' of non-integral type [-fpermissive]
// decltype(T::dur_1) T::dur_1;
// ^