Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-yield-01-multi.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test yielding an int.
5 // We will use the promise to contain this to avoid having to include
6 // additional C++ headers.
7
8 #include "../coro.h"
9
10 // boiler-plate for tests of codegen
11 #include "../coro1-ret-int-yield-int.h"
12
13 struct coro1
14 f () noexcept
15 {
16 PRINT ("f: about to yield 42");
17 co_yield 42;
18
19 PRINT ("f: about to yield 11");
20 co_yield 11;
21
22 PRINT ("f: about to return 6174");
23 co_return 6174;
24 }
25
26 int main ()
27 {
28 PRINT ("main: create coro1");
29 struct coro1 x = f ();
30 PRINT ("main: got coro1 - resuming (1)");
31 if (x.handle.done())
32 abort();
33 x.handle.resume();
34 PRINT ("main: after resume (1)");
35 int y = x.handle.promise().get_value();
36 if ( y != 42 )
37 abort ();
38 PRINT ("main: apparently got 42 - resuming (2)");
39 if (x.handle.done())
40 abort();
41 x.handle.resume();
42 PRINT ("main: after resume (2)");
43 y = x.handle.promise().get_value();
44 if ( y != 11 )
45 abort ();
46 PRINT ("main: apparently got 11 - resuming (3)");
47 if (x.handle.done())
48 {
49 PRINT ("main: done?");
50 abort();
51 }
52 x.handle.resume();
53 PRINT ("main: after resume (2) checking return");
54 y = x.handle.promise().get_value();
55 if ( y != 6174 )
56 abort ();
57 PRINT ("main: apparently got 6174");
58 if (!x.handle.done())
59 {
60 PRINT ("main: apparently not done...");
61 abort ();
62 }
63 PRINT ("main: returning");
64 return 0;
65 }