1 // { dg-do run } 2 3 // The simplest co_await we can do. 4 5 #include "../coro.h" 6 7 // boiler-plate for tests of codegen 8 #include "../coro1-ret-int-yield-int.h" 9 10 int gX = 1; 11 12 coro1 f()13f () 14 { 15 co_await coro1::suspend_always_prt{}; 16 co_return gX + 10; 17 } 18 main()19int main () 20 { 21 PRINT ("main: create coro1"); 22 struct coro1 f_coro = f (); 23 PRINT ("main: got coro1 - checking gX"); 24 if (gX != 1) 25 { 26 PRINTF ("main: gX is wrong : %d, should be 1\n", gX); 27 abort (); 28 } 29 if (f_coro.handle.done()) 30 { 31 PRINT ("main: we should not be 'done' [1]"); 32 abort (); 33 } 34 PRINT ("main: resuming [1] initial suspend"); 35 f_coro.handle.resume(); 36 PRINT ("main: resuming [2] co_await"); 37 f_coro.handle.resume(); 38 /* we should now have returned with the co_return (15) */ 39 if (!f_coro.handle.done()) 40 { 41 PRINT ("main: we should be 'done' "); 42 abort (); 43 } 44 int y = f_coro.handle.promise().get_value(); 45 if (y != 11) 46 { 47 PRINTF ("main: y is wrong : %d, should be 11\n", y); 48 abort (); 49 } 50 puts ("main: done"); 51 return 0; 52 } 53