| 1 |
// { dg-do run } |
| 2 |
// Test that we properly default-initialize the new int when () is given. |
| 3 |
|
| 4 |
#include <new> |
| 5 |
using namespace std; |
| 6 |
extern "C" void *malloc (size_t); |
| 7 |
|
| 8 |
typedef int int32_t __attribute__((mode (__SI__))); |
| 9 |
|
| 10 |
int32_t special; |
| 11 |
int32_t space = 0xdeadbeef; |
| 12 |
|
| 13 |
void *operator new (size_t size) |
| 14 |
#if __cplusplus <= 199711L |
| 15 |
throw (std::bad_alloc) |
| 16 |
#endif |
| 17 |
{ |
| 18 |
if (special) |
| 19 |
return &space; |
| 20 |
return malloc (size); |
| 21 |
} |
| 22 |
|
| 23 |
int main () |
| 24 |
{ |
| 25 |
special = 1; |
| 26 |
int32_t *p = new int32_t(); |
| 27 |
special = 0; |
| 28 |
return *p != 0; |
| 29 |
} |