[Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference.
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Mon Oct 26 10:03:09 GMT 2020
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97569
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Ah right, so
int main()
{
struct A
{
struct B *b;
struct C {} *c;
};
using U = B;
using V = C;
}
For the `struct C {}` case that explicitly defines (and declares) a new struct
in the scope of A, i.e. A::C, and so it's definitely correct that it isn't
declared in the enclosing block scope. That case is substantially different,
and all compilers agree on that.
For `struct B *b` the standard says that implicitly declares a new type, but
not as a member of A. [basic.scope.pdecl] p7 (7.2) says that the the identifier
B "is declared in the smallest namespace or block scope that contains the
declaration." And that's the block scope of main. So I think GCC is correct,
and Clang is wrong. EDG agrees with GCC FWIW.
More information about the Gcc-bugs
mailing list