gcc/testsuite/g++.dg/cpp0x/constexpr-union.C
raw| 1 | // Test that we don't have to deal with type punning |
| 2 | // DR 1188 says this is ill-formed |
| 3 | // { dg-do compile { target c++11 } } |
| 4 | |
| 5 | union U |
| 6 | { |
| 7 | float f; |
| 8 | unsigned char ca[sizeof(float)]; |
| 9 | }; |
| 10 | |
| 11 | constexpr U u = { 1.0 }; |
| 12 | constexpr float f = u.f; |
| 13 | constexpr unsigned char c = u.ca[0]; // { dg-error "U::ca" } |
| 14 | |
| 15 | constexpr double d = 1.0; |
| 16 | constexpr unsigned char c2 = (unsigned char&)d; // { dg-error "char. glvalue" } |