Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/co-await-11-forwarding.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 of forwarding a templated awaitable to co_await. | |
4 | |
5 #include "../coro.h" | |
6 | |
7 // boiler-plate for tests of codegen | |
8 #include "../coro1-ret-int-yield-int.h" | |
9 | |
10 /* Valued with an await_transform. */ | |
11 | |
12 template< typename AWAITABLE > | |
13 coro1 | |
14 test_fwd (AWAITABLE&& awaitable) | |
15 { | |
16 // the await_resume() just returns the saved int value. | |
17 int a = co_await std::forward<AWAITABLE>(awaitable); | |
18 // Which we co-return to the promise so that it can be | |
19 // retrieved. | |
20 co_return a; | |
21 } | |
22 | |
23 int main () | |
24 { | |
25 // We have an awaitable that stores the int it was constructed with. | |
26 coro1::suspend_always_intprt g(15); | |
27 struct coro1 g_coro = test_fwd (g); | |
28 | |
29 PRINT ("main: resuming g [1] (initial suspend)"); | |
30 g_coro.handle.resume(); | |
31 | |
32 PRINT ("main: resuming g [2] co_await"); | |
33 g_coro.handle.resume(); | |
34 | |
35 int y = g_coro.handle.promise().get_value(); | |
36 if (y != 15) | |
37 { | |
38 PRINTF ("main: y is wrong : %d, should be 15\n", y); | |
39 abort (); | |
40 } | |
41 puts ("main: done"); | |
42 return 0; | |
43 } |