2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.dg / eh / forced1.C
blob8f090fa9df5ea57f58c760b83ea92e0a1c277a7b
1 // { dg-do run }
3 // Test that forced unwinding runs all cleanups.  Also tests that
4 // rethrowing doesn't call the exception object destructor.
6 #include <unwind.h>
7 #include <stdlib.h>
9 static int test = 0;
11 static _Unwind_Reason_Code
12 force_unwind_stop (int version, _Unwind_Action actions,
13                    _Unwind_Exception_Class exc_class,
14                    struct _Unwind_Exception *exc_obj,
15                    struct _Unwind_Context *context,
16                    void *stop_parameter)
18   if (actions & _UA_END_OF_STACK)
19     {
20       if (test != 15)
21         abort ();
22       exit (0);
23     }
25   return _URC_NO_REASON;
28 static void
29 force_unwind_cleanup (_Unwind_Reason_Code, struct _Unwind_Exception *)
31   abort ();
34 static void force_unwind ()
36   _Unwind_Exception *exc = new _Unwind_Exception;
37   exc->exception_class = 0;
38   exc->exception_cleanup = force_unwind_cleanup;
40 #ifndef __USING_SJLJ_EXCEPTIONS__
41   _Unwind_ForcedUnwind (exc, force_unwind_stop, 0);
42 #else
43   _Unwind_SjLj_ForcedUnwind (exc, force_unwind_stop, 0);
44 #endif
46   abort ();
49 struct S
51   int bit;
52   S(int b) : bit(b) { }
53   ~S() { test |= bit; }
55   
56 static void doit ()
58   try {
59     S four(4);
61     try {
62       S one(1);
63       force_unwind ();
64   
65     } catch(...) { 
66       test |= 2;
67       throw;
68     }
70   } catch(...) {
71     test |= 8;
72     throw;
73   }
76 int main()
77
78   doit ();
79   abort ();