1 // { dg-do run } 2 3 // Test co-await in while condition. 4 5 #include "../coro.h" 6 7 // boiler-plate for tests of codegen 8 #include "../coro1-ret-int-yield-int.h" 9 10 /* An awaiter that suspends always and returns a boolean as the 11 await_resume output. */ 12 struct BoolAwaiter { 13 bool v; BoolAwaiterBoolAwaiter14 BoolAwaiter (bool _v) : v(_v) {} await_readyBoolAwaiter15 bool await_ready () { return false; } await_suspendBoolAwaiter16 void await_suspend (coro::coroutine_handle<>) {} await_resumeBoolAwaiter17 bool await_resume () { return v; } 18 }; 19 20 //extern bool tt(void); 21 int three = 3; 22 struct coro1 my_coro(bool t)23my_coro (bool t) 24 { 25 //int three = 3; 26 while (co_await BoolAwaiter (t) && t) 27 { 28 int five = three + 2; 29 co_yield 6169 + five; 30 } 31 32 co_return 42; 33 } 34 main()35int main () 36 { 37 PRINT ("main: create coro"); 38 struct coro1 x = my_coro (false); 39 40 if (x.handle.done()) 41 { 42 PRINT ("main: apparently done when we shouldn't be..."); 43 abort (); 44 } 45 46 PRINT ("main: resume initial suspend"); 47 x.handle.resume(); 48 49 // will be false - so no yield expected. 50 PRINT ("main: while condition"); 51 x.handle.resume(); 52 53 int y = x.handle.promise().get_value(); 54 if ( y != 42 ) 55 { 56 PRINTF ("main: apparently wrong value : %d\n", y); 57 abort (); 58 } 59 60 if (!x.handle.done()) 61 { 62 PRINT ("main: apparently not done..."); 63 abort (); 64 } 65 66 PRINT ("main: returning"); 67 return 0; 68 } 69