[cfe-dev] static_assert in anonymous union

Csaba Raduly via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 14 00:39:25 PST 2017


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)

I looked in Bugzilla, but all I could find was
https://bugs.llvm.org//show_bug.cgi?id=12515 (new and unassigned since
2012).

Csaba

-- 
GCS a+ e++ d- C++ ULS$ L+$ !E- W++ P+++$ w++$ tv+ b++ DI D++ 5++
The Tao of math: The numbers you can count are not the real numbers.
Life is complex, with real and imaginary parts.
"Ok, it boots. Which means it must be bug-free and perfect. " -- Linus
Torvalds
"People disagree with me. I just ignore them." -- Linus Torvalds
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170214/c9be7776/attachment.html>


More information about the cfe-dev mailing list