public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/97569] New: Declaring a struct in a field declaration of another struct.
@ 2020-10-25 16:18 anders.granlund.0 at gmail dot com
2020-10-25 22:03 ` [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2020-10-25 16:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97569
Bug ID: 97569
Summary: Declaring a struct in a field declaration of another
struct.
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: anders.granlund.0 at gmail dot com
Target Milestone: ---
Consider the following c++ program:
int main()
{
struct A
{
struct B *b;
};
using U = B;
}
Compile it with "-std=c++20 -pedantic-errors".
The gcc compiler accepts it.
Clang however rejects it with the following error
message: "unknown type name 'B': using U = B;".
The interesting thing is that if we replace struct S with struct S {} both
compilers agree on rejecting the program.
I'm not sure if this is a bug in gcc or clang, but I think this is a gcc bug.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference.
2020-10-25 16:18 [Bug c++/97569] New: Declaring a struct in a field declaration of another struct anders.granlund.0 at gmail dot com
@ 2020-10-25 22:03 ` redi at gcc dot gnu.org
2020-10-25 23:58 ` anders.granlund.0 at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-25 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97569
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Anders Granlund from comment #0)
> The interesting thing is that if we replace struct S with struct S {}
> both compilers agree on rejecting the program.
I don't see any struct S in the example program.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference.
2020-10-25 16:18 [Bug c++/97569] New: Declaring a struct in a field declaration of another struct anders.granlund.0 at gmail dot com
2020-10-25 22:03 ` [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference redi at gcc dot gnu.org
@ 2020-10-25 23:58 ` anders.granlund.0 at gmail dot com
2020-10-26 10:03 ` redi at gcc dot gnu.org
2020-10-28 8:39 ` anders.granlund.0 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2020-10-25 23:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97569
--- Comment #2 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
(In reply to Jonathan Wakely from comment #1)
> (In reply to Anders Granlund from comment #0)
> > The interesting thing is that if we replace struct S with struct S {}
> > both compilers agree on rejecting the program.
>
> I don't see any struct S in the example program.
struct B it should be.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference.
2020-10-25 16:18 [Bug c++/97569] New: Declaring a struct in a field declaration of another struct anders.granlund.0 at gmail dot com
2020-10-25 22:03 ` [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference redi at gcc dot gnu.org
2020-10-25 23:58 ` anders.granlund.0 at gmail dot com
@ 2020-10-26 10:03 ` redi at gcc dot gnu.org
2020-10-28 8:39 ` anders.granlund.0 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2020-10-26 10:03 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference.
2020-10-25 16:18 [Bug c++/97569] New: Declaring a struct in a field declaration of another struct anders.granlund.0 at gmail dot com
` (2 preceding siblings ...)
2020-10-26 10:03 ` redi at gcc dot gnu.org
@ 2020-10-28 8:39 ` anders.granlund.0 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: anders.granlund.0 at gmail dot com @ 2020-10-28 8:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97569
Anders Granlund <anders.granlund.0 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #4 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
Thanks for the explanation. I will close this bug report and report to bug to
clang instead.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-10-28 8:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-25 16:18 [Bug c++/97569] New: Declaring a struct in a field declaration of another struct anders.granlund.0 at gmail dot com
2020-10-25 22:03 ` [Bug c++/97569] Declaring a struct in a field declaration of another struct. gcc and clang difference redi at gcc dot gnu.org
2020-10-25 23:58 ` anders.granlund.0 at gmail dot com
2020-10-26 10:03 ` redi at gcc dot gnu.org
2020-10-28 8:39 ` anders.granlund.0 at gmail dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).