Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/coroutines/torture/co-yield-07-template-fn-param.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 type dependent function parms. | |
4 | |
5 #include "../coro.h" | |
6 | |
7 // boiler-plate for tests of codegen | |
8 // there is a promise ctor that takes a single int. | |
9 | |
10 #include "../coro1-ret-int-yield-int.h" | |
11 | |
12 template <typename T> | |
13 coro1 | |
14 f (T y) noexcept | |
15 { | |
16 PRINT ("coro1: about to return"); | |
17 T x = y; | |
18 co_yield x + 3; | |
19 co_return 42; | |
20 } | |
21 | |
22 int main () | |
23 { | |
24 PRINT ("main: create coro1"); | |
25 struct coro1 x = f<int>(17); | |
26 | |
27 /* We should have created the promise with an initial value of | |
28 17. */ | |
29 int y = x.handle.promise().get_value(); | |
30 if ( y != 17 ) | |
31 { | |
32 PRINTF ("main: wrong promise init (%d).", y); | |
33 abort (); | |
34 } | |
35 if (x.handle.done()) | |
36 abort(); | |
37 | |
38 PRINT ("main: got coro1 - resuming"); | |
39 x.handle.resume(); | |
40 PRINT ("main: after resume (initial suspend)"); | |
41 | |
42 if (x.handle.done()) | |
43 abort(); | |
44 | |
45 /* Now we should have the co_yielded value. */ | |
46 y = x.handle.promise().get_value(); | |
47 if ( y != 20 ) | |
48 { | |
49 PRINTF ("main: wrong result (%d).", y); | |
50 abort (); | |
51 } | |
52 | |
53 PRINT ("main: after resume (co_yield)"); | |
54 x.handle.resume(); | |
55 | |
56 /* now we should have the co_returned value. */ | |
57 y = x.handle.promise().get_value(); | |
58 if ( y != 42 ) | |
59 { | |
60 PRINTF ("main: wrong result (%d).", y); | |
61 abort (); | |
62 } | |
63 | |
64 if (!x.handle.done()) | |
65 { | |
66 PRINT ("main: apparently not done..."); | |
67 abort (); | |
68 } | |
69 PRINT ("main: returning"); | |
70 return 0; | |
71 } |