1 //  { dg-do run }
2 
3 // Check that "co_return (void)expression;" evaluates expression once.
4 
5 #include "../coro.h"
6 
7 // boiler-plate for tests of codegen
8 #define RETURN_VOID
9 #include "../coro1-ret-int-yield-int.h"
10 
11 int gX = 1;
12 __attribute__((__noinline__))
foo(void)13 int foo (void) { PRINT ("called the int fn foo"); gX +=1 ; return gX; }
14 
15 struct coro1
f()16 f () noexcept
17 {
18   PRINT ("coro1: about to return");
19   co_return (void)foo();
20 }
21 
main()22 int main ()
23 {
24   PRINT ("main: create coro1");
25   struct coro1 x = f ();
26   PRINT ("main: got coro1 - resuming");
27   if (x.handle.done())
28     abort();
29   x.handle.resume();
30   // We want to check that foo() was called exactly once.
31   if (gX != 2)
32     {
33       PRINT ("main: failed check for a single call to foo()");
34       abort ();
35     }
36   PRINT ("main: after resume");
37   if (!x.handle.done())
38     {
39       PRINT ("main: apparently not done...");
40       abort ();
41     }
42   PRINT ("main: returning");
43   return 0;
44 }
45