view gcc/testsuite/g++.dg/cpp1y/constexpr-tracking-const16.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
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 }