gcc/testsuite/g++.dg/cpp2a/constexpr-union8.C
raw| 1 | // PR c++/117614 |
| 2 | // { dg-do compile { target c++20 } } |
| 3 | |
| 4 | constexpr int |
| 5 | foo () |
| 6 | { |
| 7 | union { |
| 8 | int x{0}; |
| 9 | char y; |
| 10 | }; |
| 11 | y = 1; |
| 12 | return y; |
| 13 | } |
| 14 | |
| 15 | constexpr int |
| 16 | bar () |
| 17 | { |
| 18 | union { |
| 19 | union { |
| 20 | int x{0}; |
| 21 | char y; |
| 22 | }; |
| 23 | long long z; |
| 24 | }; |
| 25 | y = 1; |
| 26 | z = 2; |
| 27 | return z; |
| 28 | } |
| 29 | |
| 30 | static_assert (foo () == 1); |
| 31 | static_assert (bar () == 2); |