| 1 |
// https://gcc.gnu.org/PR112341 |
| 2 |
#include <coroutine> |
| 3 |
struct A { int j; }; |
| 4 |
struct B { |
| 5 |
bool await_ready(); |
| 6 |
bool await_suspend(std::coroutine_handle<>); |
| 7 |
A await_resume(); |
| 8 |
}; |
| 9 |
struct C { |
| 10 |
struct promise_type { |
| 11 |
std::suspend_always initial_suspend(); |
| 12 |
std::suspend_always final_suspend() noexcept; |
| 13 |
void unhandled_exception(); |
| 14 |
C get_return_object(); |
| 15 |
void return_void(); |
| 16 |
std::suspend_never yield_value(int x); |
| 17 |
}; |
| 18 |
}; |
| 19 |
|
| 20 |
// Similar to the above, but with a template yield_value and return_value. |
| 21 |
struct D { |
| 22 |
struct promise_type { |
| 23 |
std::suspend_always initial_suspend(); |
| 24 |
std::suspend_always final_suspend() noexcept; |
| 25 |
void unhandled_exception(); |
| 26 |
D get_return_object(); |
| 27 |
void return_value(auto); |
| 28 |
std::suspend_never yield_value(auto); |
| 29 |
}; |
| 30 |
}; |
| 31 |
|
| 32 |
template<typename> |
| 33 |
C f() { |
| 34 |
co_return; |
| 35 |
} |
| 36 |
|
| 37 |
template<typename> |
| 38 |
C g() |
| 39 |
{ |
| 40 |
co_yield 123; |
| 41 |
} |
| 42 |
|
| 43 |
template<typename> |
| 44 |
D f1() { |
| 45 |
co_return 123; |
| 46 |
} |
| 47 |
|
| 48 |
template<typename> |
| 49 |
D g1() |
| 50 |
{ |
| 51 |
co_yield 123; |
| 52 |
} |
| 53 |
|
| 54 |
void |
| 55 |
g() { |
| 56 |
f<int>(); |
| 57 |
f<bool>(); |
| 58 |
g<int>(); |
| 59 |
g<bool>(); |
| 60 |
|
| 61 |
f1<int>(); |
| 62 |
f1<bool>(); |
| 63 |
g1<int>(); |
| 64 |
g1<bool>(); |
| 65 |
} |