chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.81k stars 1.2k forks source link

use_awaitable.as_default_on(channel) compile failed #1297

Open kuntryn opened 1 year ago

kuntryn commented 1 year ago
#include <boost/asio.hpp>
#include <boost/asio/experimental/channel.hpp>

namespace asio = boost::asio;
int main(){
    asio::io_context ctx;
    typedef asio::experimental::channel<void(int)> Channel;
    std::invoke_result_t<decltype(asio::use_awaitable_t<>::as_default_on<Channel>), Channel> default_awaitable_channel{asio::use_awaitable.as_default_on(Channel{ctx})};

    return 0;
}

The above code won't compile with the following error:

external/boost/boost/asio/experimental/basic_channel.hpp:246:15: error: no matching member function for call to 'move_construct'
    service_->move_construct(impl_, *other.service_, other.impl_);
    ~~~~~~~~~~^~~~~~~~~~~~~~
external/boost/boost/asio/use_awaitable.hpp:135:12: note: in instantiation of function template specialization 'boost::asio::experimental::basic_channel<boost::asio::use_awaitable_t<>::executor_with_default<boost::asio::any_io_executor>, boost::asio::experimental::channel_traits<>, void (int)>::basic_channel<boost::asio::any_io_executor>' requested here
    return typename decay<T>::type::template rebind_executor<
           ^
test_asio.cpp:8:140: note: in instantiation of function template specialization 'boost::asio::use_awaitable_t<>::as_default_on<boost::asio::experimental::basic_channel<boost::asio::any_io_executor, boost::asio::experimental::channel_traits<>, void (int)>>' requested here
    std::invoke_result_t<decltype(asio::use_awaitable_t<>::as_default_on<Channel>), Channel> default_awaitable_channel{asio::use_awaitable.as_default_on(Channel{ctx})};
                                                                                                                                           ^
external/boost/boost/asio/experimental/detail/channel_service.hpp:101:8: note: candidate function template not viable: requires 2 arguments, but 3 were provided
  void move_construct(implementation_type<Traits, Signatures...>& impl,

https://github.com/chriskohlhoff/asio/blob/c465349fa5cd91a64bb369f5131ceacab2c0c1c3/asio/include/asio/experimental/detail/channel_service.hpp#L98-L101

It looks like the call to move_construct on this line should pass two parameters instead of three, or should call move_assign which do needs three paramters. https://github.com/chriskohlhoff/asio/blob/c465349fa5cd91a64bb369f5131ceacab2c0c1c3/asio/include/asio/experimental/basic_channel.hpp#L245 Maybe the parameters is wrongly copied from the operator= implementation. https://github.com/chriskohlhoff/asio/blob/c465349fa5cd91a64bb369f5131ceacab2c0c1c3/asio/include/asio/experimental/basic_channel.hpp#L261-L275