Debian Codegraph @

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

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test that we correctly re-write multiple uses of a function param
5 // in the body.
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 > 30)
16 {
17 PRINT ("coro1: about to return k");
18 co_return 6174;
19 }
20 else if (x > 20)
21 {
22 PRINT ("coro1: about to return the answer");
23 co_return 42;
24 }
25 else
26 {
27 PRINT ("coro1: about to return 0");
28 co_return 0;
29 }
30 }
31
32 int main ()
33 {
34 PRINT ("main: create coro1");
35 struct coro1 x = f (25);
36 PRINT ("main: got coro1 - resuming");
37 if (x.handle.done())
38 abort();
39 x.handle.resume();
40 PRINT ("main: after resume");
41 int y = x.handle.promise().get_value();
42 if ( y != 42 )
43 abort ();
44 if (!x.handle.done())
45 {
46 PRINT ("main: apparently not done...");
47 abort ();
48 }
49 PRINT ("main: returning");
50 return 0;
51 }