Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/call-03-temp-ref-co-aw.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 foo (compiler temp, co_await). | |
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 int gX = 1; | |
12 | |
13 __attribute__((__noinline__)) | |
14 static int | |
15 bar (int x, const int& y) | |
16 { | |
17 return x + y; | |
18 } | |
19 | |
20 /* Function with a compiler temporary and a co_await. */ | |
21 coro1 | |
22 g () | |
23 { | |
24 gX = bar (gX + 8, co_await 2); | |
25 co_return gX + 31; | |
26 } | |
27 | |
28 int main () | |
29 { | |
30 PRINT ("main: create coro1"); | |
31 struct coro1 g_coro = g (); | |
32 PRINT ("main: got coro1 - checking gX"); | |
33 if (gX != 1) | |
34 { | |
35 PRINTF ("main: gX is wrong : %d, should be 1\n", gX); | |
36 abort (); | |
37 } | |
38 if (g_coro.handle.done()) | |
39 { | |
40 PRINT ("main: we should not be 'done' [1]"); | |
41 abort (); | |
42 } | |
43 | |
44 PRINT ("main: resuming [1] (initial suspend)"); | |
45 g_coro.handle.resume(); | |
46 | |
47 PRINT ("main: resuming [2] (parm 1)"); | |
48 g_coro.handle.resume(); | |
49 | |
50 if (gX != 11) | |
51 { | |
52 PRINTF ("main: gX is wrong : %d, should be 11\n", gX); | |
53 abort (); | |
54 } | |
55 | |
56 /* we should now have returned with the co_return 11 + 31) */ | |
57 if (!g_coro.handle.done()) | |
58 { | |
59 PRINT ("main: we should be 'done'"); | |
60 abort (); | |
61 } | |
62 | |
63 int y = g_coro.handle.promise().get_value(); | |
64 if (y != 42) | |
65 { | |
66 PRINTF ("main: y is wrong : %d, should be 42\n", y); | |
67 abort (); | |
68 } | |
69 | |
70 puts ("main: done"); | |
71 return 0; | |
72 } |