Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-yield-07-template-fn-param.C

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