3 // Check that we correctly handle params with non-trivial DTORs and
4 // use the correct copy/move CTORs.
9 // boiler-plate for tests of codegen
10 #include "../coro1-ret-int-yield-int.h"
16 /* This is a more sophisticated awaitable... */
19 FooAwaitable(int _v) : value(_v), x(1, _v)
22 PRINTF ("FooAwaitable(%d)\n",_v);
25 FooAwaitable(const FooAwaitable& t)
30 PRINTF ("FooAwaitable(&), %d\n",value);
33 FooAwaitable(FooAwaitable&& s)
38 s.x = std::vector<int> ();
40 PRINTF ("FooAwaitable(&&), %d\n", value);
43 ~FooAwaitable() {PRINTF ("~FooAwaitable(), %d\n", value);}
45 bool await_ready() { return false; }
46 void await_suspend(coro::coroutine_handle<>) {}
47 int await_resume() { return value + x[0];}
49 void return_value(int _v) { value = _v;}
56 my_coro (FooAwaitable t_lv, FooAwaitable& t_ref, FooAwaitable&& t_rv_ref)
59 // We are created suspended, so correct operation depends on
60 // the parms being copied.
61 int sum = co_await t_lv;
63 sum += co_await t_ref;
65 // This can't work for the rvalue ref, it's always dangling.
66 //sum += co_await t_rv_ref;
67 //PRINT ("my_coro 3");
74 PRINT ("main: create coro1");
75 FooAwaitable thing (4);
76 coro1 x = my_coro (FooAwaitable (1), thing, FooAwaitable (2));
77 PRINT ("main: done ramp");
82 PRINT ("main: after resume (initial suspend)");
84 // now do the three co_awaits.
85 while(!x.handle.done())
87 PRINT ("main: after resuming 2 co_awaits");
89 /* Now we should have the co_returned value. */
90 int y = x.handle.promise().get_value();
93 PRINTF ("main: wrong result (%d).", y);
97 if (regular != 3 || copy != 0 || move != 1)
99 PRINTF ("main: unexpected ctor use (R:%d, C:%d, M:%d)\n",
100 regular, copy, move);
104 PRINT ("main: returning");