145
|
1 // { dg-do run }
|
|
2
|
|
3 // Simplest test that we correctly handle function params in the body
|
|
4 // of the coroutine. No local state, just the parm.
|
|
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 > 20)
|
|
15 {
|
|
16 PRINT ("coro1: about to return k");
|
|
17 co_return 6174;
|
|
18 }
|
|
19 else
|
|
20 {
|
|
21 PRINT ("coro1: about to return the answer");
|
|
22 co_return 42;
|
|
23 }
|
|
24 }
|
|
25
|
|
26 int main ()
|
|
27 {
|
|
28 PRINT ("main: create coro1");
|
|
29 struct coro1 x = f (32);
|
|
30 PRINT ("main: got coro1 - resuming");
|
|
31 if (x.handle.done())
|
|
32 abort();
|
|
33 x.handle.resume();
|
|
34 PRINT ("main: after resume");
|
|
35 int y = x.handle.promise().get_value();
|
|
36 if ( y != 6174 )
|
|
37 abort ();
|
|
38 if (!x.handle.done())
|
|
39 {
|
|
40 PRINT ("main: apparently not done...");
|
|
41 abort ();
|
|
42 }
|
|
43 PRINT ("main: returning");
|
|
44 return 0;
|
|
45 }
|