To clarify, GCC deliberately supports this as an extension in its default mode, which does not attempt to be a conforming ISO C++ implementation.  So that isn't a bug in itself.  The bug is that it fails to issue a diagnostic when the -pedantic option is used.

On Jul 16, 2026, at 21:22, Nate Eldredge via Std-Discussion <std-discussion@lists.isocpp.org> wrote:

Looks like this is a known bug in GCC: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=72751

On Jul 16, 2026, at 20:59, Russell Shaw via Std-Discussion <std-discussion@lists.isocpp.org> wrote:

Hi,

[class.union.anon] says "Nested types, anonymous unions, and functions
shall not be declared within an anonymous union."

It seems pretty definite. Everywhere i read and g++ allows them.

struct A {

   union {
union {
   int x;
};
   };

   A() {
int a = x;
   }
};

--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion


--
Std-Discussion mailing list
Std-Discussion@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion