Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/consteval8.C

raw
1 // { dg-do compile }
2 // { dg-options "-std=c++2a" }
3
4 struct S { consteval S () : a (1), b (2) { a++; b++; } consteval S (int x) : a (x), b (x) { a++; b--; } int a, b; };
5 S c;
6 S d = 25;
7
8 int
9 foo ()
10 {
11 S a;
12 a.b++;
13 c = a;
14 S b = 12;
15 c.a += b.a;
16 c.b += b.b;
17 S e[2];
18 S f[2] = { 1, 2 };
19 return S ().a + e[1].a + f[0].b;
20 }
21
22 constexpr S g;
23 constexpr S h = 42;
24 constexpr S i[2];
25 constexpr S j[2] = { 3, 4 };
26 static_assert (g.a == 2 && g.b == 3);
27 static_assert (h.a == 43 && h.b == 41);
28 static_assert (i[0].a == 2 && i[0].b == 3 && i[1].a == 2 && i[1].b == 3);
29 static_assert (j[0].a == 4 && j[0].b == 2 && j[1].a == 5 && j[1].b == 3);