1 // PR c++/89336
2 // { dg-do compile { target c++14 } }
3 
4 constexpr int
foo()5 foo ()
6 {
7   union U { int a; long b; };
8   union V { union U u; short v; };
9   V w {};
10   w.u.a = w.v = w.u.b = 5L;		// { dg-error "change of the active member of a union from" "" { target c++17_down } }
11   return w.u.a;
12 }
13 
14 static_assert (foo () == 5, "");	// { dg-error "non-constant condition for static assertion" "" { target c++17_down } }
15 					// { dg-message "expansion of" "" { target c++17_down } .-1 }
16 
17 constexpr int
bar()18 bar ()
19 {
20   union U { int a[5]; long b; };
21   union V { union U u; short v; };
22   V w {};
23   w.v = 5;
24   w.u.a[3] = w.u.a[1] = w.v;		// { dg-error "change of the active member of a union from" "" { target c++17_down } }
25   return w.u.a[1] + w.u.a[3];
26 }
27 
28 static_assert (bar () == 10, "");	// { dg-error "non-constant condition for static assertion" "" { target c++17_down } }
29 					// { dg-message "expansion of" "" { target c++17_down } .-1 }
30 
31 struct Z { int x, y; };
32 
33 constexpr Z
baz()34 baz ()
35 {
36   union W { Z a; long long w; };
37   W w {};
38   w.a = { 5, 0 };
39   w.a = { (int) (w.w = 17LL + w.a.x), 2 };	// { dg-error "change of the active member of a union from" "" { target c++17_down } }
40   return w.a;
41 }
42 
43 static_assert (baz ().x == 22, "");	// { dg-error "non-constant condition for static assertion" "" { target c++17_down } }
44 					// { dg-message "expansion of" "" { target c++17_down } .-1 }
45 static_assert (baz ().y == 2, "");	// { dg-error "non-constant condition for static assertion" "" { target c++17_down } }
46 					// { dg-message "expansion of" "" { target c++17_down } .-1 }
47