2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / eh / new1.C
blob4c5c684b5f2163020b8790f067ebcb2fb3e06df2
1 // PR c++/5757
2 // Test that when a constructor throws in a new-expression, we pass the
3 // right pointer to operator delete.
5 // { dg-do run }
7 #include <new>
9 int ret = 1;
11 void *ptr;
12 void * operator new[] (size_t s) throw (std::bad_alloc)
14   ptr = operator new (s);
15   return ptr;
18 void operator delete[] (void *p) throw ()
20   if (p == ptr)
21     ret = 0;
22   operator delete (p);
25 struct A
27   A() { throw 1; }
28   ~A() {}
31 int
32 main ()
34   try
35     {
36       A *p = new A[4];
37     }
38   catch (...) {}
39   return ret;