为什么最新的 clang 没有定义功能测试宏 __cpp_coroutines?

xml*_*lmx 0 c++ clang compiler-bug c++20 c++-coroutine

#include <iostream>

int main() {
#if __has_include(<coroutine>)
    std::cout << "__has_include(<coroutine>)" << std::endl;
#endif

#if defined(__cpp_impl_coroutine)
    std::cout << "__cpp_impl_coroutine is defined." << std::endl;
#endif

#if defined(__cpp_coroutines)
    std::cout << "__cpp_coroutines is defined." << std::endl;
#else
    std::cout << "__cpp_coroutines IS NOT defined!" << std::endl;
#endif
}
Run Code Online (Sandbox Code Playgroud)

我的编译器是 clang-18.1.0。

使用 构建代码clang++ -std=c++20 -stdlib=libc++ ./main.cpp,输出为:

__has_include(<coroutine>)
__cpp_impl_coroutine is defined.
__cpp_coroutines IS NOT defined!
Run Code Online (Sandbox Code Playgroud)

为什么最新的 clang 没有定义功能测试宏 __cpp_coroutines?

Ala*_*les 7

__cpp_coroutines是一个过时的功能测试宏,它在 c++20 标准化之前被拆分为__cpp_lib_coroutine和。您应该使用最新的 cpp 参考页面来获取最新信息https://en.cppreference.com/w/cpp/feature_test__cpp_impl_coroutine

__cpp_coroutines自版本 17 以来,Clang 似乎已停止定义https://godbolt.org/z/nc1GhGGTo