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