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

experimental::coro<int(int), int> doesn't compile #1596

Open
js-nano opened this issue Feb 17, 2025 · 0 comments
Open

experimental::coro<int(int), int> doesn't compile #1596

js-nano opened this issue Feb 17, 2025 · 0 comments

Comments

@js-nano
Copy link

js-nano commented Feb 17, 2025

I see a problem when I write something like (godbolt)

#include <boost/asio/any_io_executor.hpp>
#include <boost/asio/experimental/coro.hpp>

boost::asio::experimental::coro<int(int), int> my_coro(boost::asio::any_io_executor) {
    co_yield 5;
    co_return 0;
}

The error I get is:

In file included from /app/boost/include/boost/asio/experimental/coro.hpp:293,
                 from <source>:2:
/app/boost/include/boost/asio/experimental/impl/coro.hpp: In instantiation of 'auto boost::asio::experimental::detail::coro_promise_exchange<Yield, Input, Return>::yield_value(Yield&&) [with Yield = int; Input = int; Return = int]':
<source>:5:14:   required from here
    5 |     co_yield 5;
      |              ^
/app/boost/include/boost/asio/experimental/impl/coro.hpp:414:54: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'std::remove_reference<int&>::type' {aka 'int'}
  414 |         std::exchange(awaited_from, noop_coroutine())};
      |                                                      ^
Compiler returned: 1

I suspect it's a typo in coro_promise_exchange::yield_value() for the 3-type case:

auto yield_value(Yield&& y)
{
result_ = std::move(y);
return yield_input<Input>{std::move(input_),
std::exchange(awaited_from, noop_coroutine())};
}
auto yield_value(const Yield& y)
{
result_ = y;
return yield_input<Input>{std::move(input_),
std::exchange(awaited_from, noop_coroutine())};
}

which ought not have a std::move(input_), as in the 2-type case:

auto yield_value(Yield&& y)
{
result_ = std::move(y);
return yield_input<Input>{input_,
std::exchange(awaited_from, noop_coroutine())};
}
auto yield_value(const Yield& y)
{
result_ = y;
return yield_input<Input>{input_,
std::exchange(awaited_from, noop_coroutine())};
}

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