]> gcc.gnu.org Git - gcc.git/blob - gcc/testsuite/g++.dg/eh/forced3.C
libstdc++: Deprecate std::unexpected and handler functions
[gcc.git] / gcc / testsuite / g++.dg / eh / forced3.C
1 // HP-UX libunwind.so doesn't provide _UA_END_OF_STACK.
2 // { dg-do run { xfail "ia64-hp-hpux11.*" } }
3 // { dg-require-effective-target c++14_down }
4
5 // Test that forced unwinding calls std::unexpected going
6 // through a nothrow function.
7
8 #include <unwind.h>
9 #include <stdlib.h>
10 #include <exception>
11 #include <string.h>
12
13 static _Unwind_Reason_Code
14 force_unwind_stop (int version, _Unwind_Action actions,
15 _Unwind_Exception_Class exc_class,
16 struct _Unwind_Exception *exc_obj,
17 struct _Unwind_Context *context,
18 void *stop_parameter)
19 {
20 if (actions & _UA_END_OF_STACK)
21 abort ();
22 return _URC_NO_REASON;
23 }
24
25 static void __attribute__((noreturn))
26 force_unwind ()
27 {
28 _Unwind_Exception *exc = new _Unwind_Exception;
29 // exception_class might not be a scalar.
30 memset (&exc->exception_class, 0, sizeof (exc->exception_class));
31 exc->exception_cleanup = 0;
32
33 #ifndef __USING_SJLJ_EXCEPTIONS__
34 _Unwind_ForcedUnwind (exc, force_unwind_stop, 0);
35 #else
36 _Unwind_SjLj_ForcedUnwind (exc, force_unwind_stop, 0);
37 #endif
38
39 abort ();
40 }
41
42 static void
43 handle_unexpected ()
44 {
45 exit (0);
46 }
47
48 static void
49 doit () throw()
50 {
51 force_unwind ();
52 }
53
54 int main()
55 {
56 std::set_unexpected (handle_unexpected); // { dg-warning "deprecated" "" { target c++11 } }
57 doit ();
58 abort ();
59 }
This page took 0.038475 seconds and 5 git commands to generate.