C++ Logo

std-discussion

Advanced search

Re: Nested class declaration.

From: Andrew Schepler <aschepler_at_[hidden]>
Date: Thu, 4 Mar 2021 19:34:00 -0500
On Thu, Mar 4, 2021 at 4:07 PM Vladimir Grigoriev via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> In the C++ 20 Standard (Draft 4860) there is written (11.4 Class members)
>
> 5 A member shall not be declared twice in the member-specification, except that
> (5.1) — a nested class or member class template can be declared and then later defined, and
>
> It can be understood as either the enclosed class has one declaration of the nested class or it contains at first a declaration without the definition of the nested class and then a declaration that is at the same time its definition.
>
> However this declaration
>
> struct A
> {
> struct B;
> struct B {};
> struct B;
> };
>
> compiles successfully by most of compilers.
>
> Is that declaration of the structure A with the nested structure B valid or should the quote be rewritten such a way that it would be clear that such a declaration is ill-formed?

I think the Standard requirement is already quite clear: the example
is ill-formed. I see that clang and icc provide descriptive warnings
about the code by default. Yes, g++ and MSVC are non-compliant since
they don't show any diagnostics about this, even with the extra
warnings settings I tried.

-- Andrew Schepler

>
> 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

Received on 2021-03-04 18:34:16