c++: robustify testcase [PR109752]
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-tracking-const3.C
blob6853775c1e239971c5688d39fd8ecf1a958c7c72
1 // PR c++/91264
2 // { dg-do compile { target c++14 } }
4 struct A {
5   int n;
6   constexpr A() : n(1) { n = 2; }
7 };
9 struct B {
10   const A a;
11   constexpr B(bool b) {
12     if (b)
13       const_cast<A &>(a).n = 3; // { dg-error "modifying a const object" }
14     }
17 constexpr B b(false);
18 static_assert(b.a.n == 2, "");
20 constexpr B b2(true); // { dg-message "in .constexpr. expansion of " }
21 // { dg-message "originally declared" "" { target *-*-* } .-1 } 
22 static_assert((b2.a.n, 1), "");