Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-ret-14-template-3.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, typename U, typename V>
13 coro1
14 f (T x, U y, V z) noexcept
15 {
16 PRINT ("coro1: about to return");
17 T xi = (T) y;
18 T yi = (T) z;
19 T zi = x;
20 co_return 3 + xi + yi + zi;
21 }
22
23 int main ()
24 {
25 PRINT ("main: create coro1");
26 struct coro1 x = f<int, float, double>(2, 18.0F, 19.0);
27
28 /* We should be using the default promise ctor, which sets the value
29 to -1. */
30 int y = x.handle.promise().get_value();
31 if ( y != -1 )
32 {
33 PRINT ("main: wrong promise init.");
34 abort ();
35 }
36
37 PRINT ("main: got coro1 - resuming");
38 if (x.handle.done())
39 abort();
40
41 x.handle.resume();
42 PRINT ("main: after resume (initial suspend)");
43
44 /* Now we should have the co_returned value. */
45 y = x.handle.promise().get_value();
46 if ( y != 42 )
47 {
48 PRINT ("main: wrong answer.");
49 abort ();
50 }
51
52 if (!x.handle.done())
53 {
54 PRINT ("main: apparently not done...");
55 abort ();
56 }
57 PRINT ("main: returning");
58 return 0;
59 }