1 // PR c++/5757 2 // Test that when a constructor throws in a new-expression, we pass the 3 // right pointer to operator delete. 4 5 // { dg-do run } 6 7 #include <new> 8 #include <stddef.h> 9 10 int ret = 1; 11 12 void *ptr; 13 void * operator new[] (size_t s) throw (std::bad_alloc) 14 { 15 ptr = operator new (s); 16 return ptr; 17 } 18 19 void operator delete[] (void *p) throw () 20 { 21 if (p == ptr) 22 ret = 0; 23 operator delete (p); 24 } 25 26 struct A 27 { 28 A() { throw 1; } 29 ~A() {} 30 }; 31 32 int 33 main () 34 { 35 try 36 { 37 A *p = new A[4]; 38 } 39 catch (...) {} 40 return ret; 41 } 42