Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failing with G++, succeeding with clang++ #181

Open
eterchun opened this issue Oct 31, 2020 · 0 comments
Open

Test failing with G++, succeeding with clang++ #181

eterchun opened this issue Oct 31, 2020 · 0 comments

Comments

@eterchun
Copy link

When testing the following code, I am able to compile and execute when using clang++.

#include <cppcoro/generator.hpp>
#include <cppcoro/recursive_generator.hpp>
#include <iostream>
#include <type_traits>

cppcoro::generator<int> numbers(int begin, int end)
{
    for (int i = begin; i < end; ++i)
    {
        co_yield i;
    }
}

int main(int argc, char* argv[])
{
    int begin = 10;
    int end = 30;
    auto predicate = [](auto&& obj) -> bool { return true; };
    auto filter = [&pred_ = predicate](auto&& val) -> cppcoro::generator<typename std::decay_t<decltype(val)>::iterator::value_type> {
        for (auto&& _v : val) {
            if (pred_(_v)) {
                co_yield _v;
            }
        }
      };
    auto range = filter(numbers(begin, end));
    for (auto i : range) {
        std::cout << i << "\n";
    }
}

However, g++ gives the following error:

clang-test.cpp: In instantiation of ‘main(int, char**)::<lambda(auto:12&&)> [with auto:12 = cppcoro::generator<int>; typename std::decay<decltype (val)>::type::iterator::value_type = int]’:
clang-test.cpp:26:44:   required from here
clang-test.cpp:22:17: error: ‘co_yield’ cannot be used in a ‘constexpr’ function
   22 |                 co_yield _v;
      |                 ^~~~~~~~

Compilation with g++ succeeds if I remove the if statement in filter.

I am using gcc version 10.2.0 and clang version 10.0.1. I have not found an explanation for why this behavior would differ between platforms, but a solution under GCC would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant