Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/class-07-data-member.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Show that we are correctly accessing class variables.
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 int v;
14 public:
15 Foo () : v(0) {};
16 Foo (int x) : v(x) {};
17 coro1 meth ()
18 {
19 PRINT ("coro1: about to return");
20 co_return v++;
21 }
22 };
23
24 int main ()
25 {
26 Foo inst (42);
27 int y;
28 {
29 PRINT ("main: create coro1 [instance 1]");
30 coro1 x = inst.meth ();
31 if (x.handle.done())
32 abort();
33 PRINT ("main: got coro1 - resuming (initial suspend)");
34 x.handle.resume();
35 PRINT ("main: after resume");
36 y = x.handle.promise().get_value();
37 if ( y != 42 )
38 abort ();
39 if (!x.handle.done())
40 {
41 PRINT ("main: apparently not done...");
42 abort ();
43 }
44 }
45 PRINT ("main: create coro1 [instance 2]");
46 coro1 p = inst.meth ();
47 if (p.handle.done())
48 abort();
49 PRINT ("main: got coro1 - resuming (initial suspend)");
50 p.handle.resume();
51 PRINT ("main: after resume");
52 y = p.handle.promise().get_value();
53 if ( y != 43 )
54 abort ();
55 if (!p.handle.done())
56 {
57 PRINT ("main: apparently not done...");
58 abort ();
59 }
60 PRINT ("main: returning");
61 return 0;
62 }