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