comparison gcc/testsuite/g++.dg/coroutines/torture/co-await-05-loop.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 // Check correct operation of co_await in a loop without local state.
4
5 #include "../coro.h"
6
7 // boiler-plate for tests of codegen
8 #define USE_AWAIT_TRANSFORM
9 #include "../coro1-ret-int-yield-int.h"
10
11 /* Valued with an await_transform. */
12 int gX = 1;
13
14 coro1
15 f ()
16 {
17 for (;;)
18 {
19 gX += co_await 11;
20 if (gX > 100)
21 break;
22 }
23 co_return gX;
24 }
25
26 int main ()
27 {
28 PRINT ("main: create coro1");
29 struct coro1 f_coro = f ();
30 PRINT ("main: got coro1 - checking gX");
31 if (gX != 1)
32 {
33 PRINTF ("main: gX is wrong : %d, should be 1\n", gX);
34 abort ();
35 }
36 PRINT ("main: gX OK -- looping");
37 do {
38 PRINTF ("main: gX : %d \n", gX);
39 f_coro.handle.resume();
40 } while (!f_coro.handle.done());
41
42 int y = f_coro.handle.promise().get_value();
43 // first value above 100 is 10*11 + 1.
44 if (y != 111)
45 {
46 PRINTF ("main: y is wrong : %d, should be 111\n", y);
47 abort ();
48 }
49 puts ("main: done");
50 return 0;
51 }