Debian Codegraph @

gcc/testsuite/g++.dg/eh/aggregate1.C

raw
1 // PR c++/52320
2 // { dg-do run }
3
4 #if DEBUG
5 extern "C" int printf (const char *, ...);
6 #define FUNCTION_NAME __PRETTY_FUNCTION__
7 #define TRACE_FUNCTION printf ("%p->%s\n", this, FUNCTION_NAME);
8 #else
9 #define TRACE_FUNCTION
10 #endif
11 int c,d;
12 #define TRACE_CTOR TRACE_FUNCTION ++c
13 #define TRACE_DTOR TRACE_FUNCTION ++d
14
15 int throw_at = 0;
16
17 struct A {
18 A() { int i = c+1; if (i == throw_at) throw i; TRACE_CTOR; }
19 A(int i) { if (i == throw_at) throw i; TRACE_CTOR; }
20 A(const A&) { throw 10; }
21 A &operator=(const A&) { throw 11; return *this; }
22 ~A() { TRACE_DTOR; }
23 };
24
25 int fails;
26
27 void try_idx (int i)
28 {
29 #if DEBUG
30 printf ("trying %d\n", i);
31 #endif
32 throw_at = i;
33 c = d = 0;
34 int t = 10;
35 try {
36 struct X {
37 A e1[2], e2;
38 }
39 x2[3] = { { 1, 2, 3 }, { 4, 5, 6 } };
40 } catch (int x) { t = x; }
41 if (t != i || c != d || c != i-1)
42 {
43 #if DEBUG
44 printf ("%d FAIL\n", i);
45 #endif
46 ++fails;
47 }
48 }
49
50 int main()
51 {
52 for (int i = 1; i <= 10; ++i)
53 try_idx (i);
54
55 return fails;
56 }