gpt4 book ai didi

c++ - catch 内的 co_await 不再使用 GCC12 进行编译

转载 作者:行者123 更新时间:2023-12-02 18:10:24 25 4
gpt4 key购买 nike

我有一个如下所示的代码:

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();
| ^~~~~~~~

这是为什么?我该如何解决?

最佳答案

[expr.await]/2 中明确禁止这样做:

An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler ([except.pre]).

这里的错误消息非常清楚:你不能在异常处理程序中等待。它之前编译的是一个错误,这始终是规则( P0912R5 )。

关于c++ - catch 内的 co_await 不再使用 GCC12 进行编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72450588/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com