2018-10-23 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / g++.dg / eh / uncaught2.C
blob62e4d4ded225b011fc9aed57f4b926645a7a9619
1 // { dg-do compile }
2 // { dg-final { scan-assembler-not "__cxa_get_exception" } }
3 // { dg-options "-fno-use-cxa-get-exception-ptr -Wno-deprecated" }
5 #include <exception>
6 #include <cstdlib>
9 struct Check {
10   int obj1, obj2;
11   bool state;
14 static Check const data[] = {
15   { 0, 0, false },      // construct [0]
16   { 1, 0, true  },      // [1] = [0]
17   { 0, 0, true  },      // destruct [0]
18   { 2, 1, true  },      // [2] = [1]
19   { 2, 2, true  },      // destruct [2]
20   { 3, 1, true  },      // [3] = [1]
21   { 3, 3, false },      // destruct [3]
22   { 1, 1, false },      // destruct [1]
23   { 9, 9, false }       // end-of-data
26 static int pos = 0;
28 static void test(int obj1, int obj2, bool state)
30   if (obj1 != data[pos].obj1) abort ();
31   if (obj2 != data[pos].obj2) abort ();
32   if (state != data[pos].state) abort ();
33   pos++;
37 struct S {
38   int id;
39   S ();
40   S (const S &);
41   ~S ();
44 static int next_id = 0;
46 S::S()
47   : id (next_id++)
49   test (id, id, std::uncaught_exception ());
52 S::S(const S &x)
53   : id (next_id++)
55   test (id, x.id, std::uncaught_exception ());
58 S::~S()
60   test (id, id, std::uncaught_exception ());
63 extern void foo (S *);
65 int main()
67   try
68     {
69       try
70         {
71           S s0;
72           throw s0;     // s1 is the exception object
73         }
74       catch (S s2)
75         {
76           throw;
77         }
78     }
79   catch (S s3)
80     {
81     }
83   return 0;