c++clangc++20compiler-bugc++-coroutine

Why does the latest clang not define the feature test macro __cpp_coroutines?


#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
}

My compiler is clang-18.1.0.

Build the code with clang++ -std=c++20 -stdlib=libc++ ./main.cpp, and the output is:

__has_include(<coroutine>)
__cpp_impl_coroutine is defined.
__cpp_coroutines IS NOT defined!

Why does the latest clang not define the feature test macro __cpp_coroutines?


Solution

  • __cpp_coroutines is an outdated feature test macro, it was split into __cpp_lib_coroutine and __cpp_impl_coroutine before c++20 was standardised. You should use the up to date cpp reference pages for the latest information https://en.cppreference.com/w/cpp/feature_test

    Clang seems to have stopped defining __cpp_coroutines since version 17 https://godbolt.org/z/nc1GhGGTo