Debian Codegraph @

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

raw
1 // PR c++/91264
2 // { dg-do compile { target c++14 } }
3
4 struct A {
5 const int n; // { dg-message "originally declared" }
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 }
14 };
15 constexpr B b; // { dg-message "in .constexpr. expansion of " }
16 static_assert((b.a.n, 1), "");