comparison gcc/testsuite/g++.dg/coroutines/torture/co-await-19-while-cond.C @ 152:2b5abeee2509

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
comparison
equal deleted inserted replaced
145:1830386684a0 152:2b5abeee2509
1 // { dg-do run }
2
3 // Test co-await in while condition.
4
5 #include "../coro.h"
6
7 // boiler-plate for tests of codegen
8 #include "../coro1-ret-int-yield-int.h"
9
10 /* An awaiter that suspends always and returns a boolean as the
11 await_resume output. */
12 struct BoolAwaiter {
13 bool v;
14 BoolAwaiter (bool _v) : v(_v) {}
15 bool await_ready () { return false; }
16 void await_suspend (coro::coroutine_handle<>) {}
17 bool await_resume () { return v; }
18 };
19
20 //extern bool tt(void);
21 int three = 3;
22 struct coro1
23 my_coro (bool t)
24 {
25 //int three = 3;
26 while (co_await BoolAwaiter (t) && t)
27 {
28 int five = three + 2;
29 co_yield 6169 + five;
30 }
31
32 co_return 42;
33 }
34
35 int main ()
36 {
37 PRINT ("main: create coro");
38 struct coro1 x = my_coro (false);
39
40 if (x.handle.done())
41 {
42 PRINT ("main: apparently done when we shouldn't be...");
43 abort ();
44 }
45
46 PRINT ("main: resume initial suspend");
47 x.handle.resume();
48
49 // will be false - so no yield expected.
50 PRINT ("main: while condition");
51 x.handle.resume();
52
53 int y = x.handle.promise().get_value();
54 if ( y != 42 )
55 {
56 PRINTF ("main: apparently wrong value : %d\n", y);
57 abort ();
58 }
59
60 if (!x.handle.done())
61 {
62 PRINT ("main: apparently not done...");
63 abort ();
64 }
65
66 PRINT ("main: returning");
67 return 0;
68 }