[英]What is the status of C++20 coroutines support in Clang?
根据 cppreference.com ( https://en.cppreference.com/w/cpp/compiler_support#C.2B.2B20_features ) 自版本 8 以来,Clang 部分支持 C++20 协程:
但是如果在 Clang 主干(即将发布的版本 13)中,我写
#include <coroutine>
它导致错误( https://gcc.godbolt.org/z/rTfjbarKz ):
/opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/12.0.0/../../../../include/c++/12.0.0/coroutine:334:2: error: "the coroutine header requires -fcoroutines"
#error "the coroutine header requires -fcoroutines"
如果我在命令行中添加-fcoroutines
标志,那么 Clang 会抱怨( https://gcc.godbolt.org/z/qMrv6nMzE ):
clang-13: error: unknown argument: '-fcoroutines'
有什么办法可以在 Clang 中开始使用 C++20 协程吗?
请注意,第一个错误出现在 GCC 标准库中,由此可以推断-fcoroutines
选项适用于 GCC 而不是 Clang。
要使用 Clang libc++ 构建,您需要添加选项-stdlib=libc++
。 但这将导致找不到<coroutine>
头文件。
由于 Clang 协程仍处于“实验”阶段,因此您必须包含<experimental/coroutine>
。
所以有两件事你需要改变:
-stdlib=libc++
)#include <experimental/coroutine>
) 还要注意,由于协程是实验性的,头文件中定义的符号将在std::experimental
命名空间中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.