c++: copy location to AGGR_INIT_EXPR
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1y / constexpr-nsdmi7b.C
blob586ee54124cf6236e80cbaa520b4398a142e79a2
1 // PR c++/94034
2 // { dg-do compile { target c++14 } }
4 struct A
6   A() = default; A(const A&);
7   A *p = this;
8   int n = 2;
9   int m = p->n++;
12 constexpr A
13 foo()
15   return {};
18 constexpr A
19 bar()
21   A a = foo();
22   a.p->n = 5;
23   return a; // { dg-error "non-.constexpr." "" { target c++20_down } }
26 constexpr int
27 baz()
29   A b = foo();
30   b.p->n = 10;
31   A c = foo();
32   if (c.p->n != 3 || c.p->m != 2)
33     __builtin_abort();
34   foo();
35   return 0;
38 static_assert(baz() == 0, "");
40 constexpr int
41 quux()
43   const A d = foo();
44   d.p->n++; // { dg-error "const object" }
45   return 0;
48 static_assert(quux() == 0, ""); // { dg-error "non-constant" }