Debian Codegraph @

gcc/testsuite/g++.dg/eh/init-temp1.C

raw
1 // PR c++/15764
2 // { dg-do run }
3
4 #ifdef __GXX_EXPERIMENTAL_CXX0X__
5 #define NOEXCEPT_FALSE noexcept (false)
6 #else
7 #define NOEXCEPT_FALSE
8 #endif
9
10 extern "C" void abort ();
11
12 int thrown;
13
14 int as;
15 struct a {
16 a () { ++as; }
17 ~a () NOEXCEPT_FALSE { --as; if (thrown++ == 0) throw 42; }
18 };
19
20 int f (a const&) { return 1; }
21 int f (a const&, a const&) { return 1; }
22
23 int bs;
24 int as_sav;
25 struct b {
26 b (...) { ++bs; }
27 ~b () { --bs; as_sav = as; }
28 };
29
30 bool p;
31 void g()
32 {
33 if (p) throw 42;
34 }
35
36 int main () {
37 thrown = 0;
38 try {
39 b tmp(f (a(), a()));
40
41 g();
42 }
43 catch (...) {}
44
45 // We throw when the first a is destroyed, which should destroy b before
46 // the other a.
47 if (as_sav != 1)
48 abort ();
49
50 thrown = 0;
51 try {
52 b tmp(f (a()));
53
54 g();
55 }
56 catch (...) {}
57
58 if (bs != 0)
59 abort ();
60 }