Debian Codegraph @

gcc/testsuite/g++.dg/eh/new1.C

raw
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 // { dg-xfail-run-if "AIX operator new" { powerpc-ibm-aix* } }
7
8 #include <new>
9
10 int ret = 1;
11
12 void *ptr;
13 void * operator new[] (std::size_t s)
14 #if __cplusplus <= 199711L
15 throw (std::bad_alloc)
16 #endif
17 {
18 ptr = operator new (s);
19 return ptr;
20 }
21
22 void operator delete[] (void *p) throw ()
23 {
24 if (p == ptr)
25 ret = 0;
26 operator delete (p);
27 }
28
29 struct A
30 {
31 A() { throw 1; }
32 ~A() {}
33 };
34
35 int
36 main ()
37 {
38 try
39 {
40 A *p = new A[4];
41 }
42 catch (...) {}
43 return ret;
44 }