145
|
1 // PR c++/91548 - fix detecting modifying const objects for ARRAY_REF.
|
|
2 // { dg-do compile { target c++14 } }
|
|
3
|
|
4 constexpr int& impl(const int (&array)[10], int index) {
|
|
5 return const_cast<int&>(array[index]);
|
|
6 }
|
|
7
|
|
8 struct A {
|
|
9 constexpr int& operator[](int i) { return impl(elems, i); }
|
|
10 const int elems[10];
|
|
11 };
|
|
12
|
|
13 constexpr bool
|
|
14 f()
|
|
15 {
|
|
16 A arr = {};
|
|
17 arr[2] = 1; // { dg-error "modifying a const object" }
|
|
18 return false;
|
|
19 }
|
|
20
|
|
21 constexpr bool b = f(); // { dg-message "in .constexpr. expansion of " }
|
|
22 // { dg-message "originally declared" "" { target *-*-* } .-1 }
|