Debian Codegraph @

gcc/testsuite/g++.dg/coroutines/coro-range-for1.C

raw
1 // PR c++/118491
2 // { dg-do compile { target c++20 } }
3
4 #include <coroutine>
5
6 struct task {
7 struct promise_type {
8 task get_return_object() { return {}; }
9 std::suspend_always initial_suspend() { return {}; }
10 std::suspend_always final_suspend() noexcept { return {}; }
11 std::suspend_always yield_value(double value) { return {}; }
12 void unhandled_exception() { throw; }
13 };
14 };
15
16 task do_task() {
17 const int arr[]{1, 2, 3};
18
19 // No ICE if classic loop and not range-based one.
20 // for (auto i = 0; i < 10; ++i) {
21
22 // No ICE if these are moved out of the loop.
23 // auto x = std::suspend_always{};
24 // co_await x;
25
26 for (auto _ : arr) {
27 auto bar = std::suspend_always{};
28 co_await bar;
29
30 // Alternatively:
31 // auto bar = 42.;
32 // co_yield bar;
33
34 // No ICE if r-values:
35 // co_await std::suspend_always{};
36 // co_yield 42.;
37 }
38 }