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