3 // Test co-await in while condition.
7 // boiler-plate for tests of codegen
8 #include "../coro1-ret-int-yield-int.h"
10 /* An awaiter that suspends always and returns an int as the
11 await_resume output. */
15 IntAwaiter (int _v) : v(_v) {}
16 bool await_ready () { return false; }
17 void await_suspend (coro::coroutine_handle<>) {}
18 int await_resume () { return v; }
21 /* An awaiter that suspends always and returns a boolean as the
22 await_resume output. The boolean toggles on each call. */
26 BoolAwaiter (bool _v) : v(_v) {}
27 bool await_ready () { return false; }
28 void await_suspend (coro::coroutine_handle<>) {}
29 bool await_resume () { v = !v; return v; }
32 /* We will be able to establish that the second part of the conditional
33 expression is not evaluated (if it was, then we'd need an additional
34 resume to complete the coroutine). */
40 bool x = co_await IntAwaiter (t) == 5 || co_await BoolAwaiter (false);
49 PRINT ("main: create coro");
50 struct coro1 x = my_coro (5);
54 PRINT ("main: apparently done when we should not be...");
58 PRINT ("main: resume initial suspend");
61 PRINT ("main: resume IntAwaiter");
64 // The evaluation of 'co_await IntAwaiter (t) == 5' should be true, thus
65 // the second co_await in the expression will be unexecuted.
67 int y = x.handle.promise().get_value();
70 PRINTF ("main: apparently wrong value : %d\n", y);
76 PRINT ("main: apparently not done...");
79 PRINT ("main: returning");