Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/pr95519-06-grooaf.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() noexcept { return {}; }
9 constexpr std::suspend_never final_suspend() noexcept { return {}; }
10 constexpr void return_void () noexcept {}
11 constexpr void unhandled_exception() noexcept {}
12 };
13
14 int called_grooaf = 0;
15
16 struct pt_c : pt_b
17 {
18 using handle_t = std::coroutine_handle<pt_c>;
19 auto get_return_object() noexcept { return handle_t::from_promise(*this); }
20
21 static constexpr auto get_return_object_on_allocation_failure
22 = []{ PRINT("call to lambda grooaf");
23 called_grooaf++; return std::coroutine_handle<pt_c>{};
24 };
25
26 /* Provide an operator new, that always fails. */
27 void *operator new (std::size_t sz) noexcept {
28 PRINT ("promise_type: used failing op new");
29 return nullptr;
30 }
31 };
32
33 template <> struct std::coroutine_traits<pt_c::handle_t>
34 { using promise_type = pt_c; };
35
36 static pt_c::handle_t
37 foo ()
38 {
39 co_return;
40 }
41
42 int main ()
43 {
44 foo ();
45 if (called_grooaf != 1)
46 {
47 PRINT ("Failed to call grooaf");
48 abort ();
49 }
50 }