When compiling my project I get the warning anonymous types declared in an anonymous union are an extension [-Wnested-anon-types]. My code contains this union:
union
{
uint32_t m_bits; // All bits
struct
{
uint32_t significand : 23;
uint32_t exponent : 8;
uint32_t sign : 1;
} IEEE;
};
As far as other answers on the site have said, I would only expect this warning if I omitted the IEEE
, name from the struct. But currently the struct should not be an anonymous type?
Because the standard says so ([class.union.anon]):
Note: Nested types, anonymous unions, and functions cannot be declared within an anonymous union.
The wording of the warning could use some work, though. Clang allows (as a compiler extension) unnamed nested structs and additional anonymous unions within an anonymous union*, so it seems the author of the warning got just a little lazy and decided "anonymous types" was a good catch-all.
Note that giving your union
a name (thus the union is no longer anonymous) makes the warning disappear.
*Named structs are still disallowed within anonymous unions (and there's no such thing as an anonymous struct)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With