1 // { dg-do run }
2 // Testcase for proper handling of rethrow.
3
4 #include <stdio.h>
5
6 int c, d;
7 int wrong;
8
9 struct A
10 {
11 int i;
AA12 A () { i = c++; printf ("A() %d\n", i); }
AA13 A (const A&) { i = c++; printf ("A(const A&) %d\n", i); }
~AA14 ~A() { printf ("~A() %d\n", i); ++d; }
15 };
16
17 struct B
18 {
~BB19 ~B () {
20 try
21 {
22 printf ("Rethrowing III...\n");
23 throw;
24 }
25 catch (A& a)
26 {
27 printf ("Caught III %d...\n", a.i);
28 if (a.i != 1)
29 {
30 printf ("** rethrew uncaught exception **\n");
31 wrong = 1;
32 }
33 }
34 printf ("continuing to unwind II...\n");
35 }
36 };
37
38 int
main()39 main ()
40 {
41 {
42 A a;
43
44 try
45 {
46 try
47 {
48 printf ("Throwing I...\n");
49 throw a;
50 }
51 catch (A& a)
52 {
53 printf ("Caught I %d...\n", a.i);
54 try
55 {
56 B b;
57 printf ("Throwing II...\n");
58 throw a;
59 }
60 catch (A& a)
61 {
62 printf ("Caught II %d...\n", a.i);
63 printf ("Throwing IV...\n");
64 throw;
65 }
66 }
67 }
68 catch (A& a)
69 {
70 printf ("Caught IV %d.\n", a.i);
71 }
72 }
73
74 printf ("c == %d, d == %d\n", c, d);
75 return c != d || wrong;
76 }
77