2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.eh / new1.C
blob4c52cf40e4f40273c57d5c024fd548295cff85ce
1 // { dg-do run  }
2 // Test that a throw in foo destroys the A, but does not free the memory.
4 #include <cstddef>
5 #include <cstdlib>
6 #include <new>
8 struct A {
9   A();
10   ~A();
13 struct B {
14   B (A);
17 void foo (B*);
19 int newed, created;
21 int main ()
23   try {
24     foo (new B (A ()));
25   } catch (...) { }
27   return !(newed && !created);
30 A::A() { created = 1; }
31 A::~A() { created = 0; }
32 B::B(A) { }
33 void foo (B*) { throw 1; }
35 void* operator new (size_t size) throw (std::bad_alloc)
37   ++newed;
38   return (void *) std::malloc (size);
41 void operator delete (void *p) throw ()
43   --newed;
44   std::free (p);