Quantcast

static_assert in anonymous union

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

static_assert in anonymous union

Philip Reames via cfe-dev
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


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: static_assert in anonymous union

Philip Reames via cfe-dev
Csaba Raduly via cfe-dev <[hidden email]> 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.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: static_assert in anonymous union

Philip Reames via cfe-dev

On Thu, Feb 16, 2017 at 12:41 AM, Justin Bogner  wrote:

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.


​Then it must be a different bug, because mine was still present in 3.4

​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


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...