Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-98122.C

raw
1 // PR c++/98122
2 // { dg-do compile { target c++20 } }
3
4 union V { int a; char b; };
5 union W { int a; int b; };
6
7 constexpr bool
8 bar ()
9 {
10 V f { .b = 42 };
11 constexpr auto m = &V::a;
12 return (f.*m) == 42; // { dg-error "accessing 'V::a' member instead of initialized 'V::b' member in constant expression" }
13 }
14
15 constexpr bool
16 baz ()
17 {
18 W f { .b = 42 };
19 constexpr auto m = &W::b;
20 return (f.*m) == 42;
21 }
22
23 static_assert (bar (), ""); // { dg-error "non-constant condition for static assertion" }
24 // { dg-message "in .constexpr. expansion" "" { target *-*-* } .-1 }
25 static_assert (baz (), "");