Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/class-01-co-ret-parm.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Class with parm capture
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 class foo
12 {
13 public:
14 coro1 meth (int x)
15 {
16 if (x > 30)
17 {
18 PRINT ("coro1: about to return k");
19 co_return 6174;
20 }
21 else if (x > 20)
22 {
23 PRINT ("coro1: about to return the answer");
24 co_return 42;
25 }
26 else
27 {
28 PRINT ("coro1: about to return 0");
29 co_return 0;
30 }
31 }
32 };
33
34 int main ()
35 {
36 foo inst;
37
38 PRINT ("main: create coro1");
39 coro1 x = inst.meth (25);
40 if (x.handle.done())
41 abort();
42
43 x.handle.resume();
44 PRINT ("main: after resume");
45 int y = x.handle.promise().get_value();
46 if ( y != 42 )
47 {
48 PRINTF ("main: wrong result (%d)", y);
49 abort ();
50 }
51 if (!x.handle.done())
52 {
53 PRINT ("main: apparently not done...");
54 abort ();
55 }
56 PRINT ("main: returning");
57 return 0;
58 }