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