OSDN Git Service

2009-10-05 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / opt / eh4.C
1 // { dg-do run }
2 // { dg-options "-O3" }
3
4 // Make sure that the call to terminate within F2 is not eliminated
5 // by incorrect MUST_NOT_THROW optimization.  Note that we expect F1
6 // to be inlined into F2 in order to expose this case.
7
8 #include <cstdlib>
9 #include <exception>
10
11 static volatile int zero = 0;
12
13 // Note that we need F0 to not be marked nothrow, though we don't actually
14 // want a throw to happen at runtime here.  The noinline tag is merely to
15 // make sure the assembly in F0 is not unnecessarily complex.
16 static void __attribute__((noinline)) f0()
17 {
18   if (zero != 0)
19     throw 0;
20 }
21
22 struct S1
23 {
24   S1() { }
25   ~S1() { f0(); }
26 };
27
28 static void f1()
29 {
30   S1 s1;
31   throw 1;
32 }
33
34 struct S2
35 {
36   S2() { }
37   ~S2() { f1(); }
38 };
39
40 static void __attribute__((noinline)) f2()
41 {
42   S2 s2;
43   throw 2;
44 }
45
46 static void pass()
47 {
48   exit (0);
49 }
50
51 int main()
52 {
53   std::set_terminate (pass);
54   try {
55     f2();
56   } catch (...) {
57   }
58   abort ();
59 }