是否可以在 catch 子句中使用 co_await?
Is it possible to co_await in a catch clause?
以下代码:
try {
throw 42;
} catch (int i) {
co_await somefuture;
}
使用带有 -fcoroutines-ts 的 clang 6 和 7 进行编译。但是,它不会使用 Visual C++ 15 (2017) Visual C++ 16 (2019) 和 /await 进行编译,并出现错误
C2304: 'co_await' cannot be used inside of a catch block
C++20 标准草案和 cppreference 似乎没有提及任何相关内容。
它是 Microsoft 编译器中缺少的功能还是我误解了标准?
来自 [expr.await],强调我的:
An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler ([except]).
MSVC 拒绝是正确的。
以下代码:
try {
throw 42;
} catch (int i) {
co_await somefuture;
}
使用带有 -fcoroutines-ts 的 clang 6 和 7 进行编译。但是,它不会使用 Visual C++ 15 (2017) Visual C++ 16 (2019) 和 /await 进行编译,并出现错误
C2304: 'co_await' cannot be used inside of a catch block
C++20 标准草案和 cppreference 似乎没有提及任何相关内容。
它是 Microsoft 编译器中缺少的功能还是我误解了标准?
来自 [expr.await],强调我的:
An await-expression shall appear only in a potentially-evaluated expression within the compound-statement of a function-body outside of a handler ([except]).
MSVC 拒绝是正确的。