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