c++ - 是否可以在 catch 子句中使用 co_await?

标签 c++ c++20 c++-coroutine

以下代码:

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/

相关文章:

c++ - 如何读取 Linux 网络接口(interface)文件 (/etc/network/interfaces) 上的参数

c++ - 没有被引用的静态对象不会在静态库的情况下被创建?

c++ - 如何检查特定模板参数是否相同

c++ - coroutine_handle<Promise>::from_promise() 在 C++ 中的工作原理

c++ - C++ 中的 () 运算符是什么?

c++ - 如何检测 QLabel 中的文本何时更改?

c++ - 如何将 std::chrono::zoned_time 转换为 std::string

c++ - 在裸机 Controller 上的不同上下文中设置 int 变量中的标志

c++ - "With a stackless coroutine, only the top-level routine may be suspended."是什么意思

c++ - "a coroutine' s promise 必须声明 'return_value' 或 'return_void' “错误 Visual Studio 2019 C++ 20