1 // { dg-do run } 2 3 // Lambda with parm 4 5 #include "../coro.h" 6 7 // boiler-plate for tests of codegen 8 #include "../coro1-ret-int-yield-int.h" 9 main()10int main () 11 { 12 auto f = [](int x) -> coro1 13 { 14 if (x > 30) 15 { 16 PRINT ("coro1: about to return k"); 17 co_return 6174; 18 } 19 else if (x > 20) 20 { 21 PRINT ("coro1: about to return the answer"); 22 co_return 42; 23 } 24 else 25 { 26 PRINT ("coro1: about to return 0"); 27 co_return 0; 28 } 29 }; 30 31 PRINT ("main: create coro1"); 32 coro1 x = f (25); 33 PRINT ("main: got coro1 - resuming"); 34 if (x.handle.done()) 35 abort(); 36 x.handle.resume(); 37 PRINT ("main: after resume"); 38 int y = x.handle.promise().get_value(); 39 if ( y != 42 ) 40 abort (); 41 if (!x.handle.done()) 42 { 43 PRINT ("main: apparently not done..."); 44 abort (); 45 } 46 PRINT ("main: returning"); 47 return 0; 48 } 49