我有这样的代码:
auto func() -> asio::awaitable<void> {
try {
co_await async_operation();
} catch(boost::system::system_error const& e) {
co_return co_await another_async_operation();
}
}这个代码在GCC 11上运行得很好,但是与GCC 12的代码不能编译:
file.cpp:3:19: error: await expressions are not permitted in handlers
3 | co_return co_await another_async_operation();
| ^~~~~~~~那是为什么,我怎样才能修好它?
发布于 2022-05-31 15:40:05
这在[expr.await]/2中是明确禁止的。
等待表达式只能出现在处理程序(except.pre)外部的函数体的复合语句中,该表达式具有潜在的计算能力。
这里的错误消息非常清楚:不能在异常处理程序中等待。它以前编译的是一个bug,这一直是规则(P0912R5)。
https://stackoverflow.com/questions/72450588
复制相似问题