gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const22.C
raw| 1 | // PR c++/94074 - wrong modifying const object error for COMPONENT_REF. |
| 2 | // { dg-do compile { target c++14 } } |
| 3 | |
| 4 | struct X { |
| 5 | int i; |
| 6 | }; |
| 7 | |
| 8 | template <typename T> |
| 9 | struct S { |
| 10 | const X x; // { dg-message "originally declared" } |
| 11 | constexpr S(int) : x{} |
| 12 | { |
| 13 | const_cast<X&>(x).i = 19; // { dg-error "modifying a const object" } |
| 14 | } |
| 15 | }; |
| 16 | |
| 17 | constexpr S<int> p = { 10 }; |