Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/pr95519-05-gro.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 std::suspend_always initial_suspend() const noexcept { return {}; }
9 std::suspend_always final_suspend() const noexcept { return {}; }
10 constexpr void return_void () noexcept {};
11 constexpr void unhandled_exception() const noexcept {}
12 };
13
14 int called_gro_op = 0;
15
16 template<typename R, typename HandleRef, typename ...T>
17 struct std::coroutine_traits<R, HandleRef, T...> {
18 struct pt_c;
19 using promise_type = pt_c;
20 struct pt_c : pt_b {
21 //using handle_t = std::coroutine_handle<pt_c>;
22 pt_c (HandleRef h, T ...args)
23 { h = std::coroutine_handle<pt_c>::from_promise (*this);
24 PRINT ("Created Promise");
25 //g_promise = 1;
26 }
27 struct gro
28 {
29 auto operator ()() {
30 PRINT("call to operator ");
31 called_gro_op++;
32 }
33 };
34 gro get_return_object;
35 };
36 };
37
38 static void
39 foo (std::coroutine_handle<>& h)
40 {
41 co_return;
42 }
43
44 int main ()
45 {
46 std::coroutine_handle<> f;
47 foo (f);
48 if (f.done())
49 {
50 PRINT ("unexpected finished foo coro");
51 abort ();
52 }
53 f.resume();
54 if (!f.done())
55 {
56 PRINT ("expected foo to be finished");
57 abort ();
58 }
59
60 if (called_gro_op != 1)
61 {
62 PRINT ("Failed to call gro op");
63 abort ();
64 }
65 }