* arm.md (stack_tie): New insn. Use an idiom that the alias code
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.eh / new1.C
blob788a39b2958fefd50855cf29aa95c8f478a3b88f
1 // Test that a throw in foo destroys the A, but does not free the memory.
3 #include <cstddef>
4 #include <cstdlib>
5 #include <new>
7 struct A {
8   A();
9   ~A();
12 struct B {
13   B (A);
16 void foo (B*);
18 int newed, created;
20 int main ()
22   try {
23     foo (new B (A ()));
24   } catch (...) { }
26   return !(newed && !created);
29 A::A() { created = 1; }
30 A::~A() { created = 0; }
31 B::B(A) { }
32 void foo (B*) { throw 1; }
34 void* operator new (size_t size) throw (std::bad_alloc)
36   ++newed;
37   return (void *) std::malloc (size);
40 void operator delete (void *p) throw ()
42   --newed;
43   std::free (p);