comparison gcc/testsuite/g++.dg/coroutines/co-return-syntax-08-bad-return.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // { dg-additional-options "-fsyntax-only -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;
9 Coro () : handle(0) {}
10 Coro (handle_type _handle) : handle(_handle) {}
11 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;
18 ~Coro() {
19 if ( handle )
20 handle.destroy();
21 }
22 struct promise_type {
23 promise_type() {}
24 ~promise_type() {}
25 Coro get_return_object () { return Coro (handle_type::from_promise (*this)); }
26 auto initial_suspend () { return coro::suspend_always{}; }
27 auto final_suspend () { return coro::suspend_always{}; }
28 void return_void () { }
29 void unhandled_exception() { }
30 };
31 };
32
33 extern int x;
34
35 // Diagnose disallowed "return" in coroutine.
36 Coro
37 bar () // { dg-error {a 'return' statement is not allowed} }
38 {
39 if (x)
40 return Coro();
41 else
42 co_return;
43 }