Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/func-params-04.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // Test that we can manage a constructed param copy.
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #include "../coro1-ret-int-yield-int.h"
10
11 // Require a ctor.
12 struct nontriv {
13 int a, b, c;
14 nontriv (int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
15 virtual int getA () { return a; }
16 ~nontriv() { a = -1; }
17 };
18
19 struct coro1
20 f (nontriv t) noexcept
21 {
22 if (t.a > 30)
23 {
24 PRINTF ("coro1: about to return %d\n", t.b);
25 co_return t.b;
26 }
27 else if (t.a > 20)
28 {
29 PRINTF ("coro1: about to co-return %d\n", t.c);
30 co_return t.c;
31 }
32 else
33 {
34 PRINT ("coro1: about to return 0");
35 co_return 0;
36 }
37 }
38
39 int main ()
40 {
41 PRINT ("main: create coro1");
42 nontriv test (25, 6174, 42);
43 struct coro1 x = f (test);
44 PRINT ("main: got coro1 - resuming");
45 if (x.handle.done())
46 abort();
47 x.handle.resume();
48 PRINT ("main: after resume");
49 int y = x.handle.promise().get_value();
50 if ( y != 42 )
51 abort ();
52 if (!x.handle.done())
53 {
54 PRINT ("main: apparently not done...");
55 abort ();
56 }
57 PRINT ("main: returning");
58 return 0;
59 }