1 //  { dg-additional-options "-w" }
2 
3 #include "coro.h"
4 
5 struct Coro {
6   struct promise_type;
7   using handle_type = coro::coroutine_handle<Coro::promise_type>;
8   handle_type handle;
CoroCoro9   Coro () : handle(0) {}
CoroCoro10   Coro (handle_type _handle) : handle(_handle) {}
CoroCoro11   Coro (Coro &&s) : handle(s.handle) { s.handle = nullptr; }
12   Coro &operator = (Coro &&s) {
13 	handle = s.handle;
14 	s.handle = nullptr;
15 	return *this;
16   }
17   Coro (const Coro &) = delete;
~CoroCoro18   ~Coro() {
19     if ( handle )
20       handle.destroy();
21   }
22   struct promise_type {
promise_typeCoro::promise_type23   promise_type() {}
~promise_typeCoro::promise_type24   ~promise_type() {}
get_return_objectCoro::promise_type25   Coro get_return_object () { return Coro (handle_type::from_promise (*this)); }
initial_suspendCoro::promise_type26   auto initial_suspend () { return coro::suspend_always{}; }
final_suspendCoro::promise_type27   auto final_suspend () { return coro::suspend_always{}; }
return_voidCoro::promise_type28   void return_void () { }
unhandled_exceptionCoro::promise_type29    void unhandled_exception() { }
30   };
31 };
32 
33 extern int x;
34 
35 // Diagnose disallowed "return" in coroutine.
36 Coro
bar()37 bar () // { dg-error {a 'return' statement is not allowed} }
38 {
39   if (x)
40     return Coro();
41   else
42     co_return;
43 }
44