1 // { dg-do run } 2 3 // Test the ability to specialize the coroutine traits to include 4 // non-class type coroutine ramp return values. 5 6 #include "../coro.h" 7 8 int g_promise = -1; 9 10 template<typename R, typename HandleRef, typename ...T> 11 struct std::coroutine_traits<R, HandleRef, T...> { 12 struct promise_type { 13 promise_type (HandleRef h, T ...args) 14 { h = std::coroutine_handle<promise_type>::from_promise (*this); 15 PRINT ("Created Promise"); 16 g_promise = 1; 17 } 18 ~promise_type () { PRINT ("Destroyed Promise"); g_promise = 0;} 19 void get_return_object() {} 20 21 auto initial_suspend() { 22 return std::suspend_always{}; 23 } 24 auto final_suspend() noexcept { return std::suspend_never{}; } 25 26 void return_void() {} 27 void unhandled_exception() {} 28 }; 29 }; 30 31 void 32 my_coro (std::coroutine_handle<>& h) 33 { 34 PRINT ("coro1: about to return"); 35 co_return; 36 } 37 38 int main () 39 { 40 std::coroutine_handle<> h; 41 my_coro (h); 42 43 if (h.done()) 44 { 45 PRINT ("main: apparently was already done..."); 46 abort (); 47 } 48 49 // initial suspend. 50 h.resume (); 51 52 // The coro should have self-destructed. 53 if (g_promise) 54 { 55 PRINT ("main: apparently we did not complete..."); 56 abort (); 57 } 58 59 PRINT ("main: returning"); 60 return 0; 61 } 62