summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.eh/new1.C
blob: 4c52cf40e4f40273c57d5c024fd548295cff85ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// { dg-do run  }
// Test that a throw in foo destroys the A, but does not free the memory.

#include <cstddef>
#include <cstdlib>
#include <new>

struct A {
  A();
  ~A();
};

struct B {
  B (A);
};

void foo (B*);

int newed, created;

int main ()
{
  try {
    foo (new B (A ()));
  } catch (...) { }

  return !(newed && !created);
}

A::A() { created = 1; }
A::~A() { created = 0; }
B::B(A) { }
void foo (B*) { throw 1; }

void* operator new (size_t size) throw (std::bad_alloc)
{
  ++newed;
  return (void *) std::malloc (size);
}

void operator delete (void *p) throw ()
{
  --newed;
  std::free (p);
}