首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >clang-11是否通过-fcoroutines标志调用<coroutine>标头?

clang-11是否通过-fcoroutines标志调用<coroutine>标头?
EN

Stack Overflow用户
提问于 2020-11-06 03:12:33
回答 1查看 1.4K关注 0票数 7

我正在尝试通过命令编译使用coroutine库的.cpp文件。

代码语言:javascript
复制
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp 

我得到一个类似下面这样的错误:

代码语言:javascript
复制
/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"

因此,我添加了以下标志:

代码语言:javascript
复制
clang-11 -std=c++20 -stdlib=libstdc++ main.cpp -fcoroutines

现在,我得到了错误:

代码语言:javascript
复制
clang-11: error: unknown argument: '-fcoroutines'

这是一个bug吗?

最接近的问题是here。然而,我不能得出是否存在bug的结论。

对于它的价值,这里是源码:

代码语言:javascript
复制
#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";
    }
}
EN

回答 1

Stack Overflow用户

发布于 2021-05-30 11:53:34

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64703866

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档