152
|
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 E elems[N];
|
|
11 };
|
|
12
|
|
13 template <typename E, size_t N>
|
|
14 struct array2 {
|
|
15 array<E, N> a;
|
|
16 };
|
|
17
|
|
18 template <typename T>
|
|
19 struct S {
|
|
20 using U = array2<T, 4>;
|
|
21 const U m;
|
|
22 constexpr S(int) : m{}
|
|
23 {
|
|
24 const_cast<int &>(m.a[0]) = 42; // { dg-error "modifying a const object" }
|
|
25 }
|
|
26 };
|
|
27
|
|
28 constexpr S<int> p = { 10 }; // { dg-message "originally declared" }
|