c++ - clang-11 是否通过 -fcoroutines 标志调用 <coroutine> header ?

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

我正在尝试编译一个使用 coroutine 的 .cpp 文件库与命令。

clang-11 -std=c++20 -stdlib=libstdc++ main.cpp 
我收到这样的错误:
/usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/coroutine:295:2: error: "the coroutine header requires -fcoroutines"
#error "the coroutine header requires -fcoroutines"
所以,我添加了标志:
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp -fcoroutines

现在,我收到错误:
clang-11: error: unknown argument: '-fcoroutines'
这是一个错误吗?
最接近的问题是 here .但是,我无法断定是否存在错误。
对于它的值(value),这里是来源:
#include <iostream>
#include <coroutine>

template<typename T>
bool is_prime(T number) {
    for(int i=2;i<number;i++) {
        if (not i%number) return true;
    }
    return false;
}

class prime_iterator {
    unsigned int number = 2;
public:
    auto operator*() const {
        return number;
    }

    prime_iterator& operator++() {
        ++number;
        if (not is_prime(number)) {
            co_yield number;    // Trying to invoke co_yield just to see if library works.
        }
        return *this;
    }
};

auto main() -> int {
    for(prime_iterator p; *p < 30; ++p) {
        std::cout << *p << " is prime";
    }
}

最佳答案

对于 clang,它应该是 -fcoroutines-ts。除非您正在使用与 libstdc++ 混合的 clang 构建协程。

关于c++ - clang-11 是否通过 -fcoroutines 标志调用 <coroutine> header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64703866/

相关文章:

c++ - 从灰度图像到 QImage 的快速转换

c++ - "glibc detected - double free or corruption"在复杂数组的 memcpy 期间

c++ - Xcode 4.3 和 C++11 包含路径

c - 在 C 中抑制 'uninitialized variable warnings' 的不同方法

c++ - 使用带有std::jthread的静态库进行段错误(g++-10)

c++ - 获取指向模板化 lambda 运算符 () 的指针,无需捕获

c++ - CURL 在/usr/include 中,但仍然不会被 g++ 自动找到

c++ - 在完美转发函数中公开参数类型,避免代码重复

c - 在哪里可以找到有关此 .s 文件中的代码的文档?

visual-studio - Visual Studio 的/实验 :module conflicting with Vulkan's core. h 导致语法错误 - 编译失败