Debian Codegraph @

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

raw
1 // PR c++/91264
2 // { dg-do compile { target c++14 } }
3
4 struct A {
5 int n;
6 constexpr A() : n(1) { n = 2; }
7 };
8
9 struct B {
10 const A a; // { dg-message "originally declared" }
11 constexpr B(bool b) {
12 if (b)
13 const_cast<A &>(a).n = 3; // { dg-error "modifying a const object" }
14 }
15 };
16
17 constexpr B b(false);
18 static_assert(b.a.n == 2, "");
19
20 constexpr B b2(true); // { dg-message "in .constexpr. expansion of " }
21 static_assert((b2.a.n, 1), "");