Debian Codegraph @

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

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