view gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const16.C @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
line wrap: on
line source

// PR c++/91548 - fix detecting modifying const objects for ARRAY_REF.
// { dg-do compile { target c++14 } }

constexpr int& impl(const int (&array)[10], int index) {
  return const_cast<int&>(array[index]);
}

struct A {
  constexpr int& operator[](int i) { return impl(elems, i); }
  const int elems[10];
};

constexpr bool
f()
{
  A arr = {};
  arr[2] = 1; // { dg-error "modifying a const object" }
  return false;
}

constexpr bool b = f(); // { dg-message "in .constexpr. expansion of " }
// { dg-message "originally declared" "" { target *-*-* } .-1 }