Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/co-await-void_type.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 "-std=c++17 -fsyntax-only -w" } | |
2 | |
3 #include <coroutine> | |
4 | |
5 class resumable { | |
6 public: | |
7 struct promise_type; | |
8 using coro_handle = std::coroutine_handle<promise_type>; | |
9 resumable(coro_handle handle) : handle_(handle) {} | |
10 resumable(resumable&) = delete; | |
11 resumable(resumable&&) = delete; | |
12 bool resume() { | |
13 if (not handle_.done()) | |
14 handle_.resume(); | |
15 return not handle_.done(); | |
16 } | |
17 int recent_val(); | |
18 ~resumable() { handle_.destroy(); } | |
19 private: | |
20 coro_handle handle_; | |
21 }; | |
22 | |
23 struct resumable::promise_type { | |
24 int value_; | |
25 | |
26 using coro_handle = std::coroutine_handle<promise_type>; | |
27 auto get_return_object() { | |
28 return coro_handle::from_promise(*this); | |
29 } | |
30 auto initial_suspend() { return std::suspend_always(); } | |
31 auto final_suspend() { return std::suspend_always(); } | |
32 void yield_value(int v) { value_ = v; } | |
33 void unhandled_exception() {} | |
34 }; | |
35 | |
36 int resumable::recent_val(){return handle_.promise().value_;} | |
37 | |
38 resumable foo(int n){ | |
39 int x = 1; | |
40 co_await std::suspend_always(); | |
41 int y = 2; | |
42 co_yield n + x + y; // { dg-error "awaitable type 'void' is not a structure" } | |
43 } | |
44 |