https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95976
Bug ID: 95976 Summary: [[no_unique_address]] on union members has the opposite-of-intended effect Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: metaprogrammingtheworld at gmail dot com Target Milestone: --- When using [[no_unique_address]] with union members, ironically, each member is now given a unique address! Without [[no_unique_address]], the layout is as one would expect. This is particularly unfortunate since it means that a union's size grows in proportion to the number of members when using [[no_unique_address]]! Example: ////////// struct empty {}; union no_attribute_t { empty _0; empty _1; }; union with_attribute_t { [[no_unique_address]] empty _0; [[no_unique_address]] empty _1; }; constexpr no_attribute_t no_attribute{}; constexpr with_attribute_t with_attribute{}; // This succeeds static_assert( &no_attribute._0 == &no_attribute._1 ); // This fails static_assert( &with_attribute._0 == &with_attribute._1 ); //////////