1 //  { dg-do run }
2 
3 // lambda with mutable closure object.
4 
5 #include "../coro.h"
6 
7 // boiler-plate for tests of codegen
8 #include "../coro1-ret-int-yield-int.h"
9 
10 /* Creates a coro lambda with a mutable closure and
11    suspend-always initial suspend.  */
12 
make_co_lambda()13 auto make_co_lambda ()
14 {
15   return [i = 1] () mutable -> coro1 { co_return i++; };
16 }
17 
18 /* We make this behave sequentially for the purposes of testing.  */
main()19 int main()
20 {
21   auto co_l = make_co_lambda ();
22   auto v1 = co_l ();
23   auto v2 = co_l ();
24   auto v3 = co_l ();
25 
26   v3.handle.resume();
27   v2.handle.resume();
28   v1.handle.resume();
29 
30   int res1 = v1.handle.promise().get_value ();
31   int res2 = v2.handle.promise().get_value ();
32   int res3 = v3.handle.promise().get_value ();
33   PRINTF ("main: co-lambda %d, %d, %d\n",res1, res2, res3);
34   if ( res1 != 3 || res2 != 2 || res3 != 1)
35     {
36       PRINT ("main: bad return value.");
37       abort ();
38     }
39 
40   if (!v1.handle.done() || !v2.handle.done() || !v3.handle.done())
41     {
42       PRINT ("main: apparently something was not done...");
43       abort ();
44     }
45 
46   PRINT ("main: done.");
47 }
48 
49