Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/co-ret-01-void-return-is-suspend.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 "always". | |
5 | |
6 #include "../coro.h" | |
7 | |
8 struct coro1 { | |
9 struct promise_type; | |
10 using handle_type = coro::coroutine_handle<coro1::promise_type>; | |
11 handle_type handle; | |
12 coro1 () : handle(0) {} | |
13 coro1 (handle_type _handle) | |
14 : handle(_handle) { | |
15 PRINT("Created coro1 object from handle"); | |
16 } | |
17 coro1 (const coro1 &) = delete; // no copying | |
18 coro1 (coro1 &&s) : handle(s.handle) { | |
19 s.handle = nullptr; | |
20 PRINT("coro1 mv ctor "); | |
21 } | |
22 coro1 &operator = (coro1 &&s) { | |
23 handle = s.handle; | |
24 s.handle = nullptr; | |
25 PRINT("coro1 op= "); | |
26 return *this; | |
27 } | |
28 ~coro1() { | |
29 PRINT("Destroyed coro1"); | |
30 if ( handle ) | |
31 handle.destroy(); | |
32 } | |
33 | |
34 struct suspend_never_prt { | |
35 bool await_ready() const noexcept { return true; } | |
36 void await_suspend(handle_type) const noexcept { PRINT ("susp-never-susp");} | |
37 void await_resume() const noexcept { PRINT ("susp-never-resume");} | |
38 ~suspend_never_prt() {}; | |
39 }; | |
40 | |
41 struct suspend_always_prt { | |
42 bool await_ready() const noexcept { return false; } | |
43 void await_suspend(handle_type) const noexcept { PRINT ("susp-always-susp");} | |
44 void await_resume() const noexcept { PRINT ("susp-always-resume");} | |
45 }; | |
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 (always)"); | |
58 return suspend_always_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 - resuming"); | |
83 if (x.handle.done()) | |
84 abort(); | |
85 x.handle.resume(); | |
86 PRINT ("main: after resume"); | |
87 if (!x.handle.done()) | |
88 { | |
89 PRINT ("main: apparently not done..."); | |
90 abort (); | |
91 } | |
92 PRINT ("main: returning"); | |
93 return 0; | |
94 } |