Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/pr95519-07-unhandled-exception.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 #include "../coro.h"
5
6 struct pt_b
7 {
8 constexpr std::suspend_never initial_suspend() const noexcept { return {}; }
9 constexpr std::suspend_never final_suspend() const noexcept { return {}; }
10 constexpr void return_void () {};
11 };
12
13 int called_ueh_op = 0;
14 struct ueh
15 {
16 void operator ()() noexcept {
17 PRINT("call to operator UEH");
18 called_ueh_op++;
19 }
20 };
21
22 struct pt_c : pt_b
23 {
24 using handle_t = std::coroutine_handle<pt_c>;
25 auto get_return_object() noexcept { return handle_t::from_promise(*this); }
26 ueh unhandled_exception;
27 };
28
29 int lambda_ueh = 0;
30
31 struct pt_d : pt_b
32 {
33 using handle_t = std::coroutine_handle<pt_d>;
34 auto get_return_object() noexcept { return handle_t::from_promise(*this); }
35 static constexpr auto unhandled_exception
36 = [] () noexcept { PRINT("call to lambda UEH"); lambda_ueh++; };
37 };
38
39 template <>
40 struct std::coroutine_traits<pt_c::handle_t>
41 { using promise_type = pt_c; };
42
43 static pt_c::handle_t
44 foo ()
45 {
46 throw ("foo");
47 co_return;
48 }
49
50 template <>
51 struct std::coroutine_traits<pt_d::handle_t>
52 { using promise_type = pt_d; };
53
54 static pt_d::handle_t
55 bar ()
56 {
57 throw ("bar");
58 co_return;
59 }
60
61 int main ()
62 {
63 foo ();
64 bar ();
65 if (called_ueh_op != 1 || lambda_ueh != 1)
66 {
67 PRINT ("Failed to call one of the UEH cases");
68 abort ();
69 }
70 }