comparison 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
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
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 }