1// { dg-do run { xfail sparc64-*-elf arm-*-pe } }
2// { dg-options "-fexceptions" }
3// prms-id: 9706
4
5#include <stdlib.h>
6
7int count, acount;
8
9void *operator new(size_t sz) { ++count; return malloc (sz); }
10void operator delete(void *p) throw() { --count; free (p); }
11
12class A {
13public:
14  A() { ++acount; }
15  A(const A&) { ++acount; }
16  ~A() { --acount; }
17};
18
19int main() {
20  int i;
21
22  // The standard library may have called new and/or delete during
23  // startup, so we have to reset the counter here.
24  count = 0;
25
26  for( i = 0; i < 10; i++ ) {
27    try {
28      throw A();
29    }
30    catch (A& a) {
31    }
32  }
33  if (acount)
34    return 1;
35  if (count)
36    return 2;
37}
38