C++ Logo


Advanced search

inline static data members

From: Vladimir Grigoriev <vlad.moscow_at_[hidden]>
Date: Thu, 13 Feb 2020 20:53:58 +0300
There is ambiguity in the description of inline static data members.
On one hand, according to this paragraph in the C++ 20 Standard ( Static data members)
3… An inline static data member may be defined in the class definition and may specify a brace-or-equal-initializer
The word «may» is not the same as the word «shall». So it seems this code should be compiled
struct B
    static inline int x = 10;
int B::x;
But compilers say that the data member x is redefined.
On the other hand in the mentioned quote there is also written that
If the member is declared with the constexpr specifier, it may be redeclared in namespace scope with no initializer
So this code
struct B
    constexpr static int x = 10;
constexpr int B::x;
compiles successfully. But as it is said in the Standard constexpr variables are inline variables. So either the first code snippet should compile or the second code snippet shall not be compiled. Or the quote should be rewritten changing for example the word «may» to the word «shall»
With best regards
(Vlad from Moscow)
You can meet me at http://cpp.forum24.ru/ or www.stackoverflow.com or http://ru.stackoverflow.com

Received on 2020-02-13 11:56:39