Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/co-ret-00-void-return-is-ready.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-do run } | |
2 | |
3 // Basic functionality check, co_return. | |
4 // Here we check the case that initial suspend is "never", so that the co- | |
5 // routine runs to completion immediately. | |
6 | |
7 #include "../coro.h" | |
8 | |
9 struct coro1 { | |
10 struct promise_type; | |
11 using handle_type = coro::coroutine_handle<coro1::promise_type>; | |
12 handle_type handle; | |
13 coro1 () : handle(0) {} | |
14 coro1 (handle_type _handle) | |
15 : handle(_handle) { | |
16 PRINT("Created coro1 object from handle"); | |
17 } | |
18 coro1 (const coro1 &) = delete; // no copying | |
19 coro1 (coro1 &&s) : handle(s.handle) { | |
20 s.handle = nullptr; | |
21 PRINT("coro1 mv ctor "); | |
22 } | |
23 coro1 &operator = (coro1 &&s) { | |
24 handle = s.handle; | |
25 s.handle = nullptr; | |
26 PRINT("coro1 op= "); | |
27 return *this; | |
28 } | |
29 ~coro1() { | |
30 PRINT("Destroyed coro1"); | |
31 if ( handle ) | |
32 handle.destroy(); | |
33 } | |
34 | |
35 struct suspend_never_prt { | |
36 bool await_ready() const noexcept { return true; } | |
37 void await_suspend(handle_type) const noexcept { PRINT ("susp-never-susp");} | |
38 void await_resume() const noexcept {PRINT ("susp-never-resume");} | |
39 ~suspend_never_prt() {}; | |
40 }; | |
41 | |
42 struct suspend_always_prt { | |
43 bool await_ready() const noexcept { return false; } | |
44 void await_suspend(handle_type) const noexcept { PRINT ("susp-always-susp");} | |
45 void await_resume() const noexcept { PRINT ("susp-always-resume");} | |
46 }; | |
47 | |
48 struct promise_type { | |
49 promise_type() { PRINT ("Created Promise"); } | |
50 ~promise_type() { PRINT ("Destroyed Promise"); } | |
51 | |
52 coro1 get_return_object () { | |
53 PRINT ("get_return_object: from handle from promise"); | |
54 return coro1 (handle_type::from_promise (*this)); | |
55 } | |
56 auto initial_suspend () { | |
57 PRINT ("get initial_suspend (never) "); | |
58 return suspend_never_prt{}; | |
59 } | |
60 auto final_suspend () { | |
61 PRINT ("get final_suspend (always) "); | |
62 return suspend_always_prt{}; | |
63 } | |
64 void return_void () { | |
65 PRINT ("return_void ()"); | |
66 } | |
67 void unhandled_exception() { PRINT ("** unhandled exception"); } | |
68 }; | |
69 }; | |
70 | |
71 struct coro1 | |
72 f () noexcept | |
73 { | |
74 PRINT ("coro1: about to return"); | |
75 co_return; | |
76 } | |
77 | |
78 int main () | |
79 { | |
80 PRINT ("main: create coro1"); | |
81 struct coro1 x = f (); | |
82 PRINT ("main: got coro1 - should be done"); | |
83 if (!x.handle.done()) | |
84 { | |
85 PRINT ("main: apparently was not done..."); | |
86 abort (); | |
87 } | |
88 PRINT ("main: returning"); | |
89 return 0; | |
90 } |