Debian Codegraph @

gcc/testsuite/g++.dg/eh/ref-temp4.C

raw
1 // PR c++/118856
2 // { dg-do run { target c++11 } }
3 // { dg-additional-options -O2 }
4
5 int a, b, c, d;
6 struct A { A () { ++a; ++d; }; ~A () { --a; ++d; }; };
7 struct B { B (const A & = A {}) { ++b; ++d; }; ~B () { --b; ++d; }; };
8 struct C {
9 C (const B &, const A & = A {}) { ++c; ++d; throw 42; };
10 ~C () { --c; ++d; };
11 int *begin () { return nullptr; };
12 int *end () { return nullptr; };
13 };
14
15 void
16 foo ()
17 {
18 for (auto &i : C { B {} })
19 ;
20 }
21
22 int
23 main ()
24 {
25 try
26 {
27 foo ();
28 __builtin_abort ();
29 }
30 catch (int x)
31 {
32 if (x != 42 || a || b || c != 1 || d != 7)
33 __builtin_abort ();
34 }
35 }