Debian Codegraph @

gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const2.C

raw
1 // PR c++/91264
2 // { dg-do compile { target c++14 } }
3
4 struct X {
5 int j;
6 constexpr X() : j(0) { }
7 };
8
9 struct Y {
10 X x;
11 constexpr Y() : x{} { }
12 };
13
14 constexpr void
15 g ()
16 {
17 const Y y; // { dg-message "originally declared" }
18 Y *p = const_cast<Y *>(&y);
19 p->x.j = 99; // { dg-error "modifying a const object" }
20 }
21
22 static_assert((g() , 1), ""); // { dg-error "non-constant condition" }
23 // { dg-message "in 'constexpr' expansion of" "" { target *-*-* } .-1 }