Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/class-03-operator-templ-parm.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 // template parm in a class
5
6 #include "../coro.h"
7
8 // boiler-plate for tests of codegen
9 #define USE_AWAIT_TRANSFORM
10 #include "../coro1-ret-int-yield-int.h"
11
12 template <typename T>
13 class foo
14 {
15 public:
16 coro1 operator()(T y)
17 {
18 PRINT ("coro1: about to return");
19 T x = y;
20 co_return co_await x + 3;
21 }
22 };
23
24 int main ()
25 {
26 foo<int> inst {};
27 PRINT ("main: create coro1");
28 coro1 x = inst.operator()(17);
29 if (x.handle.done())
30 abort();
31
32 x.handle.resume();
33 PRINT ("main: after resume (initial suspend)");
34
35 x.handle.resume();
36 PRINT ("main: after resume (co_await)");
37
38 /* Now we should have the co_returned value. */
39 int y = x.handle.promise().get_value();
40 if ( y != 20 )
41 {
42 PRINTF ("main: wrong result (%d).", y);
43 abort ();
44 }
45
46 if (!x.handle.done())
47 {
48 PRINT ("main: apparently not done...");
49 abort ();
50 }
51 PRINT ("main: returning");
52 return 0;
53 }