Debian Codegraph @

gcc/testsuite/g++.dg/cpp2a/constexpr-new1.C

raw
1 // P0784R7
2 // { dg-do compile { target c++20 } }
3 // { dg-additional-options "-fdelete-null-pointer-checks" }
4
5 struct S { constexpr S () : s (5) {} constexpr S (int x) : s (x) {} int s; };
6
7 constexpr bool
8 foo ()
9 {
10 int r = 0;
11 S *p = new S ();
12 p->s += 3;
13 r += p->s;
14 delete p;
15 p = new S (12);
16 p->s = p->s * 2;
17 r += p->s;
18 delete p;
19 int *q = new int;
20 *q = 25;
21 r += *q;
22 delete q;
23 q = new int (1);
24 r += *q;
25 if (!q)
26 return false;
27 delete q;
28 q = new int[5]{1,2,3,4,5};
29 r += q[0] + q[4];
30 delete[] q;
31 q = new int[4];
32 q[0] = 6;
33 q[1] = 7;
34 q[3] = 8;
35 r += q[0] + q[1] + q[3];
36 delete[] q;
37 return r == 5 + 3 + 2 * 12 + 25 + 1 + 1 + 5 + 6 + 7 + 8;
38 }
39 constexpr bool a = foo ();
40 static_assert (a);