summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.other/new7.C
blob: 0c0643e62e8929c298183596e78b8fe0122417a0 (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
// { dg-do run  }
// Origin: philip_martin@ntlworld.com

#include <new>

extern "C" void abort();

bool new_flag = false;
bool delete_flag = false;

struct X {
  X()
  {
    throw 1;
  }
  void* operator new ( std::size_t n ) throw ( std::bad_alloc )
  {
    new_flag = true;
    return ::operator new( n );
  }
  void operator delete( void* p, std::size_t n ) throw()
  {
    delete_flag = true;
    ::operator delete( p );
  }
};

int
main()
{
  try
    {
      X* x = new X; // gcc 3.0 fails to call operator delete when X::X throws
    }
  catch ( ... )
    {
    }
  if ( ! new_flag || ! delete_flag )
    ::abort();
}