2018-11-07 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / opt / eh4.C
blob0a62ee2db272259bd3ef700cd987366defa2392c
1 // { dg-do run }
2 // { dg-options "-O3" }
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.
8 #include <cstdlib>
9 #include <exception>
11 static volatile int zero = 0;
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()
18   if (zero != 0)
19     throw 0;
22 struct S1
24   S1() { }
25   ~S1() { f0(); }
28 static void f1()
30   S1 s1;
31   throw 1;
34 struct S2
36   S2() { }
37   ~S2() { f1(); }
40 static void __attribute__((noinline)) f2()
42   S2 s2;
43   throw 2;
46 static void pass()
48   exit (0);
51 int main()
53   std::set_terminate (pass);
54   try {
55     f2();
56   } catch (...) {
57   }
58   abort ();