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 U m; SS22 constexpr S(int) : m{} 23 { 24 const_cast<int &>(const_cast<const U &>(m).a[0]) = 42; 25 } 26 }; 27 28 constexpr S<int> p = { 10 }; 29