以下代码:
try {
throw 42;
} catch (int i) {
co_await somefuture;
}
使用带有 -fcoroutines-ts 的 clang 6 和 7 编译。但是,它不使用 Visual C++ 15 (2017) Visual C++ 16 (2019) with/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 拒绝是正确的。
关于c++ - 是否可以在 catch 子句中使用 co_await?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55652202/