Debian Codegraph @

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

raw
1 // P0784R7
2 // { dg-do compile { target c++20 } }
3 // { dg-additional-options "-fdelete-null-pointer-checks" }
4
5 constexpr int *
6 f1 ()
7 {
8 return new int (2); // { dg-error "is not a constant expression because it refers to a result of" }
9 }
10
11 constexpr auto v1 = f1 ();
12
13 constexpr bool
14 f2 ()
15 {
16 int *p = new int (3); // { dg-error "is not a constant expression because allocated storage has not been deallocated" }
17 return false;
18 }
19
20 constexpr auto v2 = f2 ();
21
22 constexpr bool
23 f3 ()
24 {
25 int *p = new int (3);
26 int *q = p;
27 delete p;
28 delete q; // { dg-error "deallocation of already deallocated storage" }
29 return false;
30 }
31
32 constexpr auto v3 = f3 (); // { dg-message "in 'constexpr' expansion of" }
33
34 constexpr bool
35 f4 (int *p)
36 {
37 delete p; // { dg-error "destroying 'q' from outside current evaluation" }
38 return false;
39 }
40
41 int q;
42 constexpr auto v4 = f4 (&q); // { dg-message "in 'constexpr' expansion of" }
43
44 constexpr bool
45 f5 ()
46 {
47 int *p = new int; // { dg-message "allocated here" }
48 return *p == 1; // { dg-error "the content of uninitialized storage is not usable in a constant expression" }
49 }
50
51 constexpr auto v5 = f5 (); // { dg-message "in 'constexpr' expansion of" }
52
53 constexpr bool
54 f6 ()
55 {
56 int *p = new int (2); // { dg-message "allocated here" }
57 int *q = p;
58 delete p;
59 return *q == 2; // { dg-error "use of allocated storage after deallocation in a constant expression" }
60 }
61
62 constexpr auto v6 = f6 (); // { dg-message "in 'constexpr' expansion of" }
63
64 constexpr int *
65 f7 ()
66 {
67 int *p = new int (2); // { dg-error "is not a constant expression because it refers to a result of" }
68 delete p;
69 return p;
70 }
71
72 constexpr auto v7 = f7 ();
73
74 constexpr bool
75 f8_impl (int *p)
76 {
77 delete p; // { dg-error "deallocation of storage that was not previously allocated" }
78 return false;
79 }
80
81 constexpr bool
82 f8 ()
83 {
84 int q = 0;
85 return f8_impl (&q);
86 }
87 constexpr auto v8 = f8 (); // { dg-message "in 'constexpr' expansion of" }