| 1 |
// PR c++/91264 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
struct F { |
| 5 |
const int f; |
| 6 |
constexpr F() : f(9) { } |
| 7 |
}; |
| 8 |
|
| 9 |
struct C { |
| 10 |
int n; |
| 11 |
const F f; |
| 12 |
constexpr C() : n(1) { n = 66; } |
| 13 |
}; |
| 14 |
|
| 15 |
struct A { |
| 16 |
int r; |
| 17 |
const C c; // { dg-message "originally declared" } |
| 18 |
constexpr A() : r(11) { r = 14; const_cast<C &>(c).n = 42; } // { dg-error "modifying a const object" } |
| 19 |
}; |
| 20 |
|
| 21 |
struct D { |
| 22 |
const A a; |
| 23 |
constexpr D() { } // { dg-message "in .constexpr. expansion of" } |
| 24 |
}; |
| 25 |
|
| 26 |
struct E { |
| 27 |
const D d; |
| 28 |
constexpr E() { } // { dg-message "in .constexpr. expansion of" } |
| 29 |
}; |
| 30 |
|
| 31 |
struct B { |
| 32 |
const E e; |
| 33 |
constexpr B(bool) { } // { dg-message "in .constexpr. expansion of" } |
| 34 |
}; |
| 35 |
|
| 36 |
constexpr B b(false); // { dg-message "in .constexpr. expansion of" } |
| 37 |
static_assert(b.e.d.a.c.n == 2, ""); // { dg-error "non-constant condition" } |