Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/lambda-08-co-ret-parm-ref.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 // Test that we can use a function param in a co_xxxx status. | |
4 | |
5 #include "../coro.h" | |
6 | |
7 // boiler-plate for tests of codegen | |
8 #include "../coro1-ret-int-yield-int.h" | |
9 | |
10 int main () | |
11 { | |
12 int val; | |
13 | |
14 auto f = [&] (int x) -> coro1 | |
15 { | |
16 if (val + x > 25) | |
17 { | |
18 PRINT ("coro1: about to return k"); | |
19 co_return 6174; | |
20 } | |
21 else if (val + x > 20) | |
22 { | |
23 PRINTF ("coro1: about to co-return %d\n", val + x); | |
24 co_return val + x; | |
25 } | |
26 else if (val + x > 5) | |
27 { | |
28 PRINTF ("coro1: about to co-return %d\n", val); | |
29 co_return val; | |
30 } | |
31 else | |
32 { | |
33 PRINT ("coro1: about to return 0"); | |
34 co_return 0; | |
35 } | |
36 }; | |
37 | |
38 PRINT ("main: create coro1"); | |
39 | |
40 val = 20; // We should get this by ref. | |
41 int arg = 5; // and this as a regular parm. | |
42 | |
43 coro1 x = f (arg); | |
44 PRINT ("main: got coro1 - resuming"); | |
45 if (x.handle.done()) | |
46 abort(); | |
47 x.handle.resume(); | |
48 PRINT ("main: after resume"); | |
49 int y = x.handle.promise().get_value(); | |
50 if ( y != 25 ) | |
51 abort (); | |
52 if (!x.handle.done()) | |
53 { | |
54 PRINT ("main: apparently not done..."); | |
55 abort (); | |
56 } | |
57 PRINT ("main: returning"); | |
58 return 0; | |
59 } |