Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-ret-07-void-cast-expr.C

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