C++ Logo

std-discussion

Advanced search

Anonymous unions

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Fri, 17 Jul 2026 13:59:07 +1000
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;
     }
};

Received on 2026-07-17 03:59:20