C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: inline static data members
From: Brian Bi (bbi5291_at_[hidden])
Date: 2020-02-13 12:44:53


On Thu, Feb 13, 2020 at 11:54 AM Vladimir Grigoriev via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> There is ambiguity in the description of inline static data members.
>
> On one hand, according to this paragraph in the C++ 20 Standard (11.3.8.2
> 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
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>

I'm a little confused about what the relationship is between the ideas you
have written down in your message, but I think I do see your point that the
first quotation is confusing. It would be better if it said, "When an
inline static data member is declared in the class definition, the
declaration is a definition and may specify a brace-or-equal-initializer".

-- 
*Brian Bi*


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups