Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/func-params-03.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test that we can use a function param in a co_xxxx status.
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 struct coro1
12 f (int x) noexcept
13 {
14 if (x > 30)
15 {
16 PRINT ("coro1: about to return k");
17 co_return 6174;
18 }
19 else if (x > 20)
20 {
21 PRINTF ("coro1: about to co-return %d", x);
22 co_return x;
23 }
24 else
25 {
26 PRINT ("coro1: about to return 0");
27 co_return 0;
28 }
29 }
30
31 int main ()
32 {
33 PRINT ("main: create coro1");
34 struct coro1 x = f (25);
35 PRINT ("main: got coro1 - resuming");
36 if (x.handle.done())
37 abort();
38 x.handle.resume();
39 PRINT ("main: after resume");
40 int y = x.handle.promise().get_value();
41 if ( y != 25 )
42 abort ();
43 if (!x.handle.done())
44 {
45 PRINT ("main: apparently not done...");
46 abort ();
47 }
48 PRINT ("main: returning");
49 return 0;
50 }