Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-ret-13-template-2.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 #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 __attribute__((__unused__)) T x = y;
18 co_return 3;
19 }
20
21 int main ()
22 {
23 PRINT ("main: create coro1");
24 struct coro1 x = f<int>(17);
25
26 /* We should have created the promise with an initial value of
27 17. */
28 int y = x.handle.promise().get_value();
29 if ( y != 17 )
30 {
31 PRINT ("main: wrong promise init.");
32 abort ();
33 }
34
35 PRINT ("main: got coro1 - resuming");
36 if (x.handle.done())
37 abort();
38
39 x.handle.resume();
40 PRINT ("main: after resume (initial suspend)");
41
42 /* Now we should have the co_returned value. */
43 y = x.handle.promise().get_value();
44 if ( y != 3 )
45 {
46 PRINT ("main: wrong answer.");
47 abort ();
48 }
49
50 if (!x.handle.done())
51 {
52 PRINT ("main: apparently not done...");
53 abort ();
54 }
55 PRINT ("main: returning");
56 return 0;
57 }