1 // { dg-do run } 2 3 // Test that we correctly re-write multiple uses of a function param 4 // in the body. 5 6 #include "../coro.h" 7 8 // boiler-plate for tests of codegen 9 #include "../coro1-ret-int-yield-int.h" 10 11 struct coro1 f(int x)12f (int x) noexcept 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 main()31int main () 32 { 33 PRINT ("main: create coro1"); 34 struct coro1 x = f (25); 35 PRINT ("main: got coro1 - resuming"); 36 if (x.handle.done()) 37 abort(); 38 x.handle.resume(); 39 PRINT ("main: after resume"); 40 int y = x.handle.promise().get_value(); 41 if ( y != 42 ) 42 abort (); 43 if (!x.handle.done()) 44 { 45 PRINT ("main: apparently not done..."); 46 abort (); 47 } 48 PRINT ("main: returning"); 49 return 0; 50 } 51