aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/init/aggr7-eh.C
blob: db45e15d9af70074d17e12712434362b227e6c23 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
// PR c++/50866, adjusted
// { dg-do run }

#if __cplusplus > 201100L
#define THROWING noexcept(false)
#else
#define THROWING
#endif

extern "C" void abort ();

int a;
int d = -1;
struct A {
  A() { ++a; }
  A(const A&);
  ~A() THROWING {
    --a;
    if (a == d)
      throw (short)a;
  }
};
int b;
int t;
struct B {
  B(const char *, const A& = A())
  {
    if (b == t)
      throw b;
    ++b;
    if (a != b) abort ();
  }
  B(const B&);
  ~B()
  {
    --b;
  }
};
struct C {
  B b1, b2, b3;
};
void f()
{
  try
    {
      C c = { "a","b","c" };
      if (a != 0) abort ();
      if (b != 3) abort ();
    }
  catch (int i) { }
  catch (short s) { }
  if (a != 0) abort ();
  if (b != 0) abort ();
}

int main()
{
  for (t = 0; t <= 3; ++t)
    f();
  for (d = 0; d <= 2; ++d)
    f();
}