summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.eh/rethrow6.C
blob: ce9962605c95dd21c799217c4db5774de3b40bd3 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// { dg-do run  }
// Testcase for proper handling of rethrow.

#include <stdio.h>

int c, d;
int wrong;

struct A
{
  int i;
  A () { i = c++; printf ("A() %d\n", i); }
  A (const A&) { i = c++; printf ("A(const A&) %d\n", i); }
  ~A() { printf ("~A() %d\n", i); ++d; }
};

struct B
{
  ~B () {
    try
      {
	printf ("Rethrowing III...\n");
	throw;
      }
    catch (A& a)
      {
	printf ("Caught III %d...\n", a.i);
	if (a.i != 1)
	  {
	    printf ("** rethrew uncaught exception **\n");
	    wrong = 1;
	  }
      }
    printf ("continuing to unwind II...\n");
  }
};

int
main ()
{
  {
    A a;

    try
      {
	try
	  {
	    printf ("Throwing I...\n");
	    throw a;
	  }
	catch (A& a)
	  {
	    printf ("Caught I %d...\n", a.i);
	    try
	      {
		B b;
		printf ("Throwing II...\n");
		throw a;
	      }
	    catch (A& a)
	      {
		printf ("Caught II %d...\n", a.i);
		printf ("Throwing IV...\n");
		throw;
	      }
	  }
      }
    catch (A& a)
      {
	printf ("Caught IV %d.\n", a.i);
      }
  }

  printf ("c == %d, d == %d\n", c, d);
  return c != d || wrong;
}