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