constexpr static member before/after C++17

This change is due to the inline variables proposal (P0386). static constexpr will imply inline, making definitions redundant.

In Annex D, add a new subclause, “Redeclaration of static constexpr data members”, D.X, with the following content:
For compatibility with prior C++ International Standards, a constexpr static data member may be redundantly redeclared outside the class with no initializer. This usage is deprecated.

[Example:

struct A {
static constexpr int n = 5; // definition (declaration in C++2014)
};
const int A::n; // redundant declaration (definition in C++2014)

—end example]

Regarding to your questions:

Has this change other reasons than making the additional definitions useless?

In essence, no. Yet it has additional uses besides the one you noted (see this question). This proposal was controversial because it might encourage the use of a mutable global state.

Will it apply on const static member or not?

No. Unless you annotate it as inline.

does it all hold also for the situation at Class:J with constexpr functions?

Yes. The proposal deals with linking but does not affect initialization rules.

Leave a Comment