1 // { dg-do run } 2 3 #include "../coro.h" 4 5 struct pt_b 6 { initial_suspendpt_b7 std::suspend_never initial_suspend() const noexcept { return {}; } final_suspendpt_b8 std::suspend_never final_suspend() const noexcept { return {}; } unhandled_exceptionpt_b9 void unhandled_exception() const noexcept {} 10 }; 11 12 int called_rv_op = 0; 13 struct rv 14 { operatorrv15 void operator ()(){ 16 PRINT("call to operator "); 17 called_rv_op++; 18 } 19 }; 20 21 struct pt_c : pt_b 22 { 23 using handle_t = std::coroutine_handle<pt_c>; get_return_objectpt_c24 auto get_return_object() noexcept { return handle_t::from_promise(*this); } 25 rv return_void; 26 }; 27 28 int called_lambda = 0; 29 30 struct pt_d : pt_b 31 { 32 using handle_t = std::coroutine_handle<pt_d>; get_return_objectpt_d33 auto get_return_object() noexcept { return handle_t::from_promise(*this); } 34 static constexpr auto return_void 35 = []{ PRINT("call to lambda "); called_lambda++; }; 36 }; 37 38 template <> struct std::coroutine_traits<pt_c::handle_t> 39 { using promise_type = pt_c; }; 40 41 static pt_c::handle_t foo () 42 { 43 co_return; 44 } 45 46 template <> struct std::coroutine_traits<pt_d::handle_t> 47 { using promise_type = pt_d; }; 48 49 static pt_d::handle_t bar () 50 { 51 co_return; 52 } 53 54 int main () 55 { 56 foo (); 57 bar (); 58 if (called_rv_op != 1 || called_lambda != 1) 59 { 60 PRINT ("Failed to call one of the return_void cases"); 61 abort (); 62 } 63 } 64