C++ Logo

std-discussion

Advanced search

Re: Nested class declaration.

From: Vishal Oza <vickoza_at_[hidden]>
Date: Thu, 4 Mar 2021 20:10:27 -0600
I would like to ask "is the last *struct B;* declaration still valid?" I
see that the first as forward declaration, the second is a definition, the
third could be an unnamed instance but I am not sure. Checked on Godbolt
"Compiler Explorer" except for GCC most instants of the struct A get
optimized out.

On Thu, Mar 4, 2021 at 3: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?
>
> 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 20:11:26