Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/co-yield-08-more-refs.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Check co_return co_await
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 /* Tests for . */
12 struct test
13 {
14 auto operator co_await() & noexcept {
15 return coro1::suspend_always_intprt{};
16 }
17
18 auto operator co_await() && noexcept {
19 return coro1::suspend_always_longprtsq(3L);
20 }
21 };
22
23 struct coro1
24 f (test thing) noexcept
25 {
26 co_yield co_await static_cast<test&&>(thing);
27 co_return 6174;
28 }
29
30 int main ()
31 {
32 PRINT ("main: create coro1");
33
34 struct coro1 x = f (test{});
35 if (x.handle.done())
36 abort();
37
38 PRINT ("main: resuming (initial suspend)");
39 x.handle.resume();
40 PRINT ("main: resuming (await intprt)");
41 x.handle.resume();
42
43 int y = x.handle.promise().get_value();
44 if ( y != 9 )
45 {
46 PRINTF ("main: co-yield gave %d, should be 9\n", y);
47 abort ();
48 }
49
50 PRINT ("main: got coro1 - resuming (co_yield)");
51 if (x.handle.done())
52 abort();
53 x.handle.resume();
54
55 y = x.handle.promise().get_value();
56 if ( y != 6174 )
57 {
58 PRINTF ("main: co-return gave %d, should be 9\n", y);
59 abort ();
60 }
61
62 if (!x.handle.done())
63 {
64 PRINT ("main: apparently not done...");
65 abort ();
66 }
67 PRINT ("main: returning");
68 return 0;
69 }