Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/local-var-02-conditional.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test local vars in nested scopes
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
12 f (int x) noexcept
13 {
14 int y = x;
15 const int test = 20;
16 if (y > test)
17 {
18 int fred = y - 20;
19 PRINTF ("coro1: about to return %d\n", fred);
20 co_return fred;
21 }
22 else
23 {
24 PRINT ("coro1: about to return the answer\n");
25 co_return y;
26 }
27
28 co_return x;
29 }
30
31 int main ()
32 {
33 PRINT ("main: create coro1");
34 struct coro1 x = f (6194);
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 != 6174 )
42 abort ();
43 if (!x.handle.done())
44 {
45 PRINT ("main: apparently not done...");
46 abort ();
47 //x.handle.resume();
48 }
49 PRINT ("main: returning");
50 return 0;
51 }