145
|
1 // { dg-do run }
|
|
2
|
|
3 // Test that we can manage a constructed param reference
|
|
4
|
|
5 #include "../coro.h"
|
|
6
|
|
7 // boiler-plate for tests of codegen
|
|
8 #include "../coro1-ret-int-yield-int.h"
|
|
9
|
|
10 // Require a ctor.
|
|
11 struct nontriv {
|
|
12 int a, b, c;
|
|
13 nontriv (int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
|
|
14 virtual int getA () { return a; }
|
|
15 };
|
|
16
|
|
17 struct coro1
|
|
18 f (nontriv &t) noexcept
|
|
19 {
|
|
20 if (t.a > 30)
|
|
21 {
|
|
22 PRINTF ("coro1: about to return %d", t.b);
|
|
23 co_return t.b;
|
|
24 }
|
|
25 else if (t.a > 20)
|
|
26 {
|
|
27 PRINTF ("coro1: about to co-return %d", t.c);
|
|
28 co_return t.c;
|
|
29 }
|
|
30 else
|
|
31 {
|
|
32 PRINT ("coro1: about to return 0");
|
|
33 co_return 0;
|
|
34 }
|
|
35 }
|
|
36
|
|
37 int main ()
|
|
38 {
|
|
39 PRINT ("main: create coro1");
|
|
40 nontriv test (25, 6174, 42);
|
|
41 struct coro1 x = f (test);
|
|
42 PRINT ("main: got coro1 - resuming");
|
|
43 if (x.handle.done())
|
|
44 abort();
|
|
45 x.handle.resume();
|
|
46 PRINT ("main: after resume");
|
|
47 int y = x.handle.promise().get_value();
|
|
48 if ( y != 42 )
|
|
49 abort ();
|
|
50 if (!x.handle.done())
|
|
51 {
|
|
52 PRINT ("main: apparently not done...");
|
|
53 abort ();
|
|
54 }
|
|
55 PRINT ("main: returning");
|
|
56 return 0;
|
|
57 }
|