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

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // PR c++/94074 - wrong modifying const object error for COMPONENT_REF.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 // { dg-do compile { target c++14 } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 typedef decltype (sizeof (0)) size_t;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 template <typename E, size_t N>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 struct array
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 constexpr const E &operator[](size_t n) const noexcept { return elems[n]; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 E elems[N];
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13 template <typename E, size_t N>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 struct array2 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 array<E, N> a;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 template <typename T>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 struct S {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20 using U = array2<T, 4>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 U m;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 constexpr S(int) : m{}
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 const_cast<int &>(const_cast<const U &>(m).a[0]) = 42;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 constexpr S<int> p = { 10 };