| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for stdlib size_t" { ! hostedlib } } |
| 3 |
|
| 4 |
// Origin: Mark Mitchell <[email protected]> |
| 5 |
|
| 6 |
#include <stdlib.h> |
| 7 |
|
| 8 |
struct S { |
| 9 |
~S (); |
| 10 |
}; |
| 11 |
|
| 12 |
bool flag; |
| 13 |
S* s1; |
| 14 |
S* s2; |
| 15 |
|
| 16 |
void* operator new (size_t s) |
| 17 |
{ |
| 18 |
return malloc (s); |
| 19 |
} |
| 20 |
|
| 21 |
void operator delete (void* p) |
| 22 |
{ |
| 23 |
if (flag && p != s2) |
| 24 |
abort (); |
| 25 |
} |
| 26 |
|
| 27 |
S::~S () { |
| 28 |
if (this != s2) |
| 29 |
abort (); |
| 30 |
s1 = 0; |
| 31 |
} |
| 32 |
|
| 33 |
int main () { |
| 34 |
s2 = new S; |
| 35 |
s1 = s2; |
| 36 |
// Turn on the check in `operator delete'. |
| 37 |
flag = true; |
| 38 |
delete s1; |
| 39 |
// Turn it off again so that normal shutdown code works. |
| 40 |
flag = false; |
| 41 |
} |
| 42 |
|