| 1 |
// { dg-do run } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } |
| 3 |
|
| 4 |
// GROUPS passed scoping |
| 5 |
// scoping file |
| 6 |
// From: [email protected] (Sheetal V. Kakkad) |
| 7 |
// Date: Tue, 5 Oct 93 12:38:49 -0500 |
| 8 |
// Subject: G++ 2.4.5 - global delete operator not called when using "::delete" |
| 9 |
// Message-ID: <[email protected]> |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <stddef.h> |
| 13 |
#include <stdlib.h> |
| 14 |
|
| 15 |
class foo |
| 16 |
{ |
| 17 |
public: |
| 18 |
foo () { ; } |
| 19 |
~foo () { ; } |
| 20 |
void *operator new (size_t); |
| 21 |
void operator delete (void *); |
| 22 |
}; |
| 23 |
|
| 24 |
void *foo::operator new (size_t size) |
| 25 |
{ |
| 26 |
return malloc (size); |
| 27 |
} |
| 28 |
|
| 29 |
int overloaded_delete = 0; |
| 30 |
|
| 31 |
void foo::operator delete (void *data) |
| 32 |
{ |
| 33 |
free ((char *) data); |
| 34 |
overloaded_delete++; |
| 35 |
} |
| 36 |
|
| 37 |
int main () |
| 38 |
{ |
| 39 |
foo *f = new foo; |
| 40 |
foo *ff = ::new foo; |
| 41 |
::delete ff; // should call the default delete operator |
| 42 |
delete f; |
| 43 |
if (overloaded_delete == 1) |
| 44 |
printf ("PASS\n"); |
| 45 |
else |
| 46 |
{ printf ("FAIL\n"); return 1; } |
| 47 |
} |