xml*_*lmx 7 c++ gcc compiler-errors coroutine c++20
#include <coroutine>
#include <string>
template<typename T>
struct Awaiter final {
bool await_ready() const { return false; }
void await_suspend(std::coroutine_handle<>) const {}
T await_resume() const { return T{}; }
};
struct ReturnObject {
struct promise_type {
ReturnObject get_return_object() { return {}; }
std::suspend_never initial_suspend()
noexcept { return {}; }
std::suspend_never final_suspend()
noexcept { return {}; }
void return_void() {}
void unhandled_exception() {}
};
};
ReturnObject f()
{
auto a1 = Awaiter<int>{};
[[maybe_unused]] auto v1 = co_await a1; // ok
auto a2 = Awaiter<std::string>{};
[[maybe_unused]] auto v2 = co_await a2; // error
}
int main() { f(); }
Run Code Online (Sandbox Code Playgroud)
请参阅:在线演示
错误信息:
error: no suspend point info for ''co_await' not supported
by dump_decl<declaration error>'
37 | [[maybe_unused]] auto v2 = co_await a2; // error
| ^~~~~~~~
Run Code Online (Sandbox Code Playgroud)
为什么 co_await 不能返回字符串?