Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/torture/pr95003.C

raw
1 // { dg-do run }
2 // { dg-skip-if "requires hosted libstdc++ for cstdlib abort" { ! hostedlib } }
3
4 #include "../coro.h"
5 #include "../coro1-ret-int-yield-int.h"
6
7 // This tests that, when we insert bind scopes to contain variables that
8 // have been promoted from compiler temporaries to extend their lifetimes
9 // to a containing full expression, the inserted bind scopes have their
10 // tree-side-effects set.
11
12 struct Awaitable {
13 int v;
14 Awaitable (int _v) : v(_v) {}
15 bool await_ready() { return false; }
16 void await_suspend(std::coroutine_handle<coro1::promise_type>) {}
17 int await_resume() { return v; }
18 auto operator co_await() { return *this; }
19 };
20
21 coro1
22 my_coro
23 (int x)
24 {
25 int sum = 0;
26 for (unsigned i = 0; i < 100; ++i) {
27 sum += co_await Awaitable{x+1};
28 }
29 co_return sum;
30 }
31
32 int main ()
33 {
34 PRINT ("main: create coro1");
35 struct coro1 f_coro = my_coro (0);
36
37 PRINT ("main: OK -- looping");
38
39 do {
40 f_coro.handle.resume();
41 } while (!f_coro.handle.done());
42
43 int y = f_coro.handle.promise().get_value();
44 if (y != 100)
45 {
46 PRINTF ("main: y is wrong : %d, should be 100\n", y);
47 abort ();
48 }
49 PRINT ("main: done");
50 return 0;
51 }