Debian Codegraph @

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

raw
1 // PR c++/118874
2 // { dg-do compile }
3 // { dg-additional-options "-std=c++20" }
4
5 #include <coroutine>
6
7 struct B {
8 bool await_ready () const noexcept;
9 void await_suspend (std::coroutine_handle<> h) const noexcept;
10 void await_resume () const noexcept;
11 };
12
13 struct C {
14 struct promise_type {
15 const char *value;
16 std::suspend_never initial_suspend ();
17 std::suspend_always final_suspend () noexcept;
18 void return_value (const char *v);
19 void unhandled_exception ();
20 C get_return_object () { return C{this}; }
21 };
22 promise_type *p;
23 explicit C (promise_type *p) : p(p) {}
24 const char *get ();
25 };
26
27 C
28 bar (bool x)
29 {
30 if (x)
31 co_await B{};
32 co_return "foobar";
33 }