1 //  { dg-do run }
2 
3 // Test yielding an int.
4 // We will use the promise to contain this to avoid having to include
5 // additional C++ headers.
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
f()13 f () noexcept
14 {
15   PRINT ("f: about to yield 42");
16   co_yield 42;
17 
18   PRINT ("f: about to yield 11");
19   co_yield 11;
20 
21   PRINT ("f: about to return 6174");
22   co_return 6174;
23 }
24 
main()25 int main ()
26 {
27   PRINT ("main: create coro1");
28   struct coro1 x = f ();
29   PRINT ("main: got coro1 - resuming (1)");
30   if (x.handle.done())
31     abort();
32   x.handle.resume();
33   PRINT ("main: after resume (1)");
34   int y = x.handle.promise().get_value();
35   if ( y != 42 )
36     abort ();
37   PRINT ("main: apparently got 42 - resuming (2)");
38   if (x.handle.done())
39     abort();
40   x.handle.resume();
41   PRINT ("main: after resume (2)");
42   y = x.handle.promise().get_value();
43   if ( y != 11 )
44     abort ();
45   PRINT ("main: apparently got 11 - resuming (3)");
46   if (x.handle.done())
47     {
48    PRINT ("main: done?");
49    abort();
50     }
51   x.handle.resume();
52   PRINT ("main: after resume (2) checking return");
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 }
65