145
|
1 // { dg-do run }
|
|
2
|
|
3 // Check co_return co_await
|
|
4
|
|
5 #include "../coro.h"
|
|
6
|
|
7 // boiler-plate for tests of codegen
|
|
8 #define USE_AWAIT_TRANSFORM
|
|
9 #include "../coro1-ret-int-yield-int.h"
|
|
10
|
|
11 __attribute__((__noinline__))
|
|
12 static int
|
|
13 foo (int x)
|
|
14 {
|
|
15 return x + 2;
|
|
16 }
|
|
17
|
|
18 /* Function with a single await. */
|
|
19 struct coro1
|
|
20 f () noexcept
|
|
21 {
|
|
22 PRINT ("f: about to yield");
|
|
23 co_yield foo (co_await 40);
|
|
24
|
|
25 PRINT ("f: about to return 6174");
|
|
26 co_return 6174;
|
|
27 }
|
|
28
|
|
29 int main ()
|
|
30 {
|
|
31 PRINT ("main: create coro1");
|
|
32 struct coro1 x = f ();
|
|
33 if (x.handle.done())
|
|
34 abort();
|
|
35
|
|
36 PRINT ("main: resuming (initial suspend)");
|
|
37 x.handle.resume();
|
|
38 PRINT ("main: resuming (await intprt)");
|
|
39 x.handle.resume();
|
|
40
|
|
41 PRINT ("main: after resume (2)");
|
|
42 int y = x.handle.promise().get_value();
|
|
43 if ( y != 42 )
|
|
44 abort ();
|
|
45 PRINT ("main: apparently got 42");
|
|
46
|
|
47 PRINT ("main: got coro1 - resuming (co_yield)");
|
|
48 if (x.handle.done())
|
|
49 abort();
|
|
50 x.handle.resume();
|
|
51
|
|
52 PRINT ("main: after resume (co_yield)");
|
|
53 y = x.handle.promise().get_value();
|
|
54 if ( y != 6174 )
|
|
55 abort ();
|
|
56 PRINT ("main: apparently got 6174");
|
|
57 if (!x.handle.done())
|
|
58 {
|
|
59 PRINT ("main: apparently not done...");
|
|
60 abort ();
|
|
61 }
|
|
62 PRINT ("main: returning");
|
|
63 return 0;
|
|
64 }
|