public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++
@ 2024-02-14 15:00 tsqurt at outlook dot com
2024-02-14 15:04 ` [Bug c++/113919] " mpolacek at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: tsqurt at outlook dot com @ 2024-02-14 15:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113919
Bug ID: 113919
Summary: Nested anonymous unions should be prohibited in ISO
C++
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: tsqurt at outlook dot com
Target Milestone: ---
Created attachment 57425
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57425&action=edit
example.cpp
Anonymous unions shall not be declared within an anonymous union. But gcc never
warns about this.
Demo source code as a C++17 source file attached. Note: attached code is a
valid C
source code but not a valid C++ source code. GCC is expected to REJECT or WARN,
but it compiles without any message.
$gcc example.cpp -std=c++17 --pedantic -Wall -Wextra
expect:
warning: ISO C++ prohibits anonymous unions within anonymous unions[-Wpedantic]
But gcc exited with code 0, leaving empty message.
Reference: N4849, Working Draft, Standard for Programming Language C++, Chapter
11, Section 5.1 Anonymous unions. (Different versions of modern C++
specification mention this issue in their correspondent chapters.)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113919] Nested anonymous unions should be prohibited in ISO C++
2024-02-14 15:00 [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++ tsqurt at outlook dot com
@ 2024-02-14 15:04 ` mpolacek at gcc dot gnu.org
2024-02-14 15:26 ` mpolacek at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-14 15:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113919
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2024-02-14
Status|UNCONFIRMED |NEW
Keywords| |accepts-invalid
Ever confirmed|0 |1
CC| |mpolacek at gcc dot gnu.org
--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
[class.union.anon]/1: Nested types, anonymous unions, and functions shall not
be declared within an anonymous union.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113919] Nested anonymous unions should be prohibited in ISO C++
2024-02-14 15:00 [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++ tsqurt at outlook dot com
2024-02-14 15:04 ` [Bug c++/113919] " mpolacek at gcc dot gnu.org
@ 2024-02-14 15:26 ` mpolacek at gcc dot gnu.org
2024-02-14 16:00 ` mpolacek at gcc dot gnu.org
2024-02-14 16:26 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-14 15:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113919
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I suppose this should fix it but there are testsuite FAILs.
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -5522,6 +5522,12 @@ fixup_anonymous_aggr (tree t)
}
}
}
+ /* [class.union.anon]/1: Nested types, anonymous unions, and functions
+ shall not be declared within an anonymous union. */
+ else if (ANON_UNION_TYPE_P (TREE_TYPE (probe)))
+ pedwarn (DECL_SOURCE_LOCATION (probe), OPT_Wpedantic,
+ "anonymous unions cannot be declared within an anonymous "
+ "union");
}
/* Splice all functions out of CLASSTYPE_MEMBER_VEC. */
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113919] Nested anonymous unions should be prohibited in ISO C++
2024-02-14 15:00 [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++ tsqurt at outlook dot com
2024-02-14 15:04 ` [Bug c++/113919] " mpolacek at gcc dot gnu.org
2024-02-14 15:26 ` mpolacek at gcc dot gnu.org
@ 2024-02-14 16:00 ` mpolacek at gcc dot gnu.org
2024-02-14 16:26 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-14 16:00 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113919
--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
clang++ has -Wnested-anon-types so I think we need that too.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/113919] Nested anonymous unions should be prohibited in ISO C++
2024-02-14 15:00 [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++ tsqurt at outlook dot com
` (2 preceding siblings ...)
2024-02-14 16:00 ` mpolacek at gcc dot gnu.org
@ 2024-02-14 16:26 ` mpolacek at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2024-02-14 16:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113919
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |DUPLICATE
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Ah, we have a dup.
*** This bug has been marked as a duplicate of bug 72751 ***
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-14 16:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 15:00 [Bug c++/113919] New: Nested anonymous unions should be prohibited in ISO C++ tsqurt at outlook dot com
2024-02-14 15:04 ` [Bug c++/113919] " mpolacek at gcc dot gnu.org
2024-02-14 15:26 ` mpolacek at gcc dot gnu.org
2024-02-14 16:00 ` mpolacek at gcc dot gnu.org
2024-02-14 16:26 ` mpolacek at gcc dot gnu.org
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).