Debian Codegraph @

gcc/testsuite/g++.dg/opt/eh4.C

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