| 1 |
// { dg-additional-options "-Wall" } |
| 2 |
|
| 3 |
#include <coroutine> |
| 4 |
|
| 5 |
template <typename _Tp> struct promise; |
| 6 |
template <typename _Tp> struct task { |
| 7 |
using promise_type = promise<_Tp>; |
| 8 |
bool await_ready() noexcept { return false; } |
| 9 |
void await_suspend(std::coroutine_handle<> awaiter) noexcept { m_a = awaiter; } |
| 10 |
auto await_resume() { return _Tp(); } |
| 11 |
std::coroutine_handle<> m_a; |
| 12 |
}; |
| 13 |
|
| 14 |
template <typename _Tp> struct promise { |
| 15 |
auto get_return_object() noexcept { return task<_Tp>(); } |
| 16 |
auto initial_suspend() noexcept { return std::suspend_always(); } |
| 17 |
auto final_suspend() noexcept { return std::suspend_always(); } |
| 18 |
void return_value(_Tp value) noexcept { m_v = value; } |
| 19 |
void unhandled_exception() noexcept {} |
| 20 |
_Tp m_v; |
| 21 |
}; |
| 22 |
|
| 23 |
task<int> test_coro(void) { |
| 24 |
int r = 0; |
| 25 |
#if 1 |
| 26 |
// this code causes the unexpected warning below |
| 27 |
r += co_await task<int>(); |
| 28 |
#else |
| 29 |
// this code causes no warning |
| 30 |
auto b = co_await task<int>(); |
| 31 |
r += b; |
| 32 |
#endif |
| 33 |
co_return r; |
| 34 |
// test1.cpp: In function ‘task<int> test_coro(int)’: |
| 35 |
// test1.cpp:36:1: warning: statement has no effect [-Wunused-value] |
| 36 |
// 36 | } |
| 37 |
// | ^ |
| 38 |
} |
| 39 |
|
| 40 |
int main(void) { |
| 41 |
return 0; |
| 42 |
} |