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

Using a generator returned as r-value doesn't work with std::ranges | operator in release #41

Open
MelisWillem opened this issue Feb 28, 2022 · 0 comments

Comments

@MelisWillem
Copy link

I am using "Microsoft (R) C/C++ Optimizing Compiler Version 19.29.30136 for x64" with "Conan version 1.43.4" on the package "andreasbuhr-cppcoro/cci.20210113".

#include <cppcoro/generator.hpp>
#include <ranges>

cppcoro::generator<int> generate() {
    for (int i = 0; i < 10; ++i) {
        co_yield i;
    }
}

void WhereThingsAreOk() {
    auto g = generate();
    for (auto j :
         g | std::views::transform([](int x) -> int { return x * 2; })) {
    }
}

void WhereThingsGoWrong() {
    for (auto j : generate() | std::views::transform(
                                   [](int x) -> int { return x * 2; })) {
    }
}

When I use a generator (or recursive generator same problem) that is an r-value in a foreach (like in "WhereThingsGoWrong") it only works when I compile in debug. But when I compile in Release I get the following error:

error C2678: binary '|': no operator found which takes a left-hand operand of type 'cppcoro::generator<int>' (or there is no acceptable conversion)
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xfilesystem_abi.h(229): note: could be '__std_fs_copy_options operator |(__std_fs_copy_options,__std_fs_copy_options) noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xfilesystem_abi.h(204): note: or       '__std_fs_file_flags operator |(__std_fs_file_flags,__std_fs_file_flags) noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xfilesystem_abi.h(196): note: or       '__std_access_rights operator |(__std_access_rights,__std_access_rights) noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xfilesystem_abi.h(122): note: or       '__std_fs_stats_flags operator |(__std_fs_stats_flags,__std_fs_stats_flags) noexcept'
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include\xfilesystem_abi.h(79): note: or       '__std_fs_file_attr operator |(__std_fs_file_attr,__std_fs_file_attr) noexcept'
blah.cpp(21): note: while trying to match the argument list '(cppcoro::generator<int>, std::ranges::views::_Transform_fn::_Partial<_Fn>)'
        with
        [
            _Fn=WhereThingsGoWrong::<lambda_1>
        ]
blah.cpp(20): error C3531: 'j': a symbol whose type contains 'auto' must have an initializer
blah.cpp(20): error C2143: syntax error: missing ';' before ':'
blah.cpp(20): error C2088: '|': illegal for class
blah.cpp(21): error C2143: syntax error: missing ';' before ')'

Can someone explain what's going on here? It looks to me like the sfinae is different when compiling in release, is this on purpose? Am I missing something?

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