152
|
1 // PR c++/94034
|
|
2 // { dg-do compile { target c++14 } }
|
|
3
|
|
4 struct A
|
|
5 {
|
|
6 A *p = this;
|
|
7 int n = 2;
|
|
8 int m = p->n++;
|
|
9 };
|
|
10
|
|
11 constexpr A
|
|
12 foo()
|
|
13 {
|
|
14 return {};
|
|
15 }
|
|
16
|
|
17 constexpr A
|
|
18 bar()
|
|
19 {
|
|
20 A a = foo();
|
|
21 a.p->n = 5;
|
|
22 return a;
|
|
23 }
|
|
24
|
|
25 static_assert(bar().n == 5, "");
|
|
26
|
|
27 constexpr int
|
|
28 baz()
|
|
29 {
|
|
30 A b = foo();
|
|
31 b.p->n = 10;
|
|
32 A c = foo();
|
|
33 if (c.p->n != 3 || c.p->m != 2)
|
|
34 __builtin_abort();
|
|
35 bar();
|
|
36 return 0;
|
|
37 }
|
|
38
|
|
39 static_assert(baz() == 0, "");
|
|
40
|
|
41 constexpr int
|
|
42 quux()
|
|
43 {
|
|
44 const A d = foo();
|
|
45 d.p->n++; // { dg-error "const object" }
|
|
46 return 0;
|
|
47 }
|
|
48
|
|
49 static_assert(quux() == 0, ""); // { dg-error "non-constant" }
|