Debian Codegraph @

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

raw
1 // PR libstdc++/10606
2 // { dg-do run }
3 // { dg-options "-Wno-deprecated" }
4 // { dg-options "-fuse-cxa-get-exception-ptr -Wno-deprecated" { target powerpc*-*-darwin* } }
5 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
6
7 #include <exception>
8 #include <cstdlib>
9
10
11 struct Check {
12 int obj1, obj2;
13 bool state;
14 };
15
16 static Check const data[] = {
17 { 0, 0, false }, // construct [0]
18 { 1, 0, false }, // [1] = [0]
19 { 0, 0, true }, // destruct [0]
20 { 2, 1, true }, // [2] = [1]
21 { 2, 2, true }, // destruct [2]
22 { 3, 1, true }, // [3] = [1]
23 { 3, 3, false }, // destruct [3]
24 { 1, 1, false }, // destruct [1]
25 { 9, 9, false } // end-of-data
26 };
27
28 static int pos = 0;
29
30 static void test(int obj1, int obj2, bool state)
31 {
32 if (obj1 != data[pos].obj1) abort ();
33 if (obj2 != data[pos].obj2) abort ();
34 if (state != data[pos].state) abort ();
35 pos++;
36 }
37
38
39 struct S {
40 int id;
41 S ();
42 S (const S &);
43 ~S ();
44 };
45
46 static int next_id = 0;
47
48 S::S()
49 : id (next_id++)
50 {
51 test (id, id, std::uncaught_exception ());
52 }
53
54 S::S(const S &x)
55 : id (next_id++)
56 {
57 test (id, x.id, std::uncaught_exception ());
58 }
59
60 S::~S()
61 {
62 test (id, id, std::uncaught_exception ());
63 }
64
65 extern void foo (S *);
66
67 int main()
68 {
69 try
70 {
71 try
72 {
73 S s0;
74 throw s0; // s1 is the exception object
75 }
76 catch (S s2)
77 {
78 throw;
79 }
80 }
81 catch (S s3)
82 {
83 }
84
85 return 0;
86 }