view gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const17.C @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
line wrap: on
line source

// PR c++/94074 - wrong modifying const object error for COMPONENT_REF.
// { dg-do compile { target c++14 } }

typedef decltype (sizeof (0)) size_t;

template <typename E, size_t N>
struct array
{
  constexpr const E &operator[](size_t n) const noexcept { return elems[n]; }
  E elems[N];
};

template <typename T>
struct S {
  using U = array<T, 4>;
  U m;
  constexpr S(int) : m{}
  {
    const_cast<int &>(const_cast<const U &>(m)[0]) = 42;
  }
};

constexpr S<int> p = { 10 };