| 1 |
// PR c++/94074 - wrong modifying const object error for COMPONENT_REF. |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
typedef decltype (sizeof (0)) size_t; |
| 5 |
|
| 6 |
template <typename E, size_t N> |
| 7 |
struct array |
| 8 |
{ |
| 9 |
constexpr const E &operator[](size_t n) const noexcept { return elems[n]; } |
| 10 |
const E elems[N]; // { dg-message "originally declared" } |
| 11 |
}; |
| 12 |
|
| 13 |
template <typename T> |
| 14 |
struct S { |
| 15 |
using U = array<T, 4>; |
| 16 |
U m; |
| 17 |
constexpr S(int) : m{} |
| 18 |
{ |
| 19 |
const_cast<int &>(const_cast<const U &>(m)[0]) = 42; // { dg-error "modifying a const object" } |
| 20 |
} |
| 21 |
}; |
| 22 |
|
| 23 |
constexpr S<int> p = { 10 }; |