Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-await-10-template-fn-arg.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 #define USE_AWAIT_TRANSFORM
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_return co_await x + 3;
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
36 PRINT ("main: got coro1 - resuming");
37 if (x.handle.done())
38 abort();
39
40 x.handle.resume();
41 PRINT ("main: after resume (initial suspend)");
42
43 x.handle.resume();
44 PRINT ("main: after resume (co_await)");
45
46 /* Now we should have the co_returned 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 if (!x.handle.done())
55 {
56 PRINT ("main: apparently not done...");
57 abort ();
58 }
59 PRINT ("main: returning");
60 return 0;
61 }