[cfe-dev] static_assert in anonymous union
Justin Bogner via cfe-dev
cfe-dev at lists.llvm.org
Wed Feb 15 15:41:56 PST 2017
Csaba Raduly via cfe-dev <cfe-dev at lists.llvm.org> writes:
> I have the following code:
>
> #include <stdint.h>
>
> struct RTI {
> char name[16];
>
> struct bits {
> uint8_t u : 1;
> uint8_t k : 1;
> uint32_t pad : 30;
> };
>
> union {
> uint32_t all_bits;
> bits my_bits;
> static_assert(sizeof(my_bits) == sizeof(all_bits), "Wrong number of
> bits");
> };
>
> };
>
> Ubuntu 14's clang 3.4 fails to compile this:
>
> $ /usr/bin/clang++ -v -std=c++11 stass.cc
> Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM
> 3.4)
> Target: x86_64-pc-linux-gnu
> Thread model: posix
> ...
> stass.cc:15:9: error: anonymous union can only contain non-static data
> members
> static_assert(sizeof(my_bits) == sizeof(all_bits), "Wrong number of
> bits");
> ^
> 1 error generated.
>
> However, ToT clang version 5.0.0 (trunk 294435), and every GCC version I've
> thrown at it (4.8, 5.3, 6.3, 7.0) compiles it fine.
>
> Does anybody know which version fixed this? (godbolt.org suggests 3.5)
If 3.4 fails and 3.5 works, doesn't that pretty strongly imply that 3.5
fixed it? Maybe I don't understand your question.
> I looked in Bugzilla, but all I could find was
> https://bugs.llvm.org//show_bug.cgi?id=12515 (new and unassigned since
> 2012).
Looks like that was fixed in 3.3 or so - I've updated the bug.
More information about the cfe-dev
mailing list