chriskohlhoff / asio

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

BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT makes channels incompatible with any_completion_handler #1398

Open anarthal opened 9 months ago

anarthal commented 9 months ago

Version: Boost 1.84 Compiler: clang++16, under Ubuntu 22.04, -std=c++20, debug Caught by Boost.MySQL, which has introduced a feature using channels and any_completion_handler.

Sample program:

#define BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT

#include <boost/asio/any_completion_handler.hpp>
#include <boost/asio/experimental/channel.hpp>
#include <boost/system/error_code.hpp>

namespace asio = boost::asio;
using boost::system::error_code;

void f(asio::experimental::channel<void(error_code)>& chan)
{
    chan.async_receive(asio::any_completion_handler<void(error_code)>([](...) {}));
}

int main() {}

Fails with the following error:


[main] Building folder: testground 
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/ruben/workspace/mysql/private/test-programs/testground/build --config Debug --target all -j 6 --
[build] Consolidate compiler generated dependencies of target main
[build] [ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
[build] In file included from /home/ruben/workspace/mysql/private/test-programs/testground/main.cpp:4:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/channel.hpp:23:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/basic_channel.hpp:24:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_service.hpp:25:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_receive_op.hpp:23:
[build] /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_operation.hpp:103:22: error: cannot form a reference to 'void'
[build]   const executor_type& get_executor() const noexcept
[build]                      ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_operation.hpp:235:3: note: in instantiation of template class 'boost::asio::experimental::detail::channel_operation::handler_work_base<boost::asio::executor, boost::asio::executor>' requested here
[build]   channel_operation::handler_work_base<
[build]   ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_receive_op.hpp:119:56: note: in instantiation of template class 'boost::asio::experimental::detail::channel_operation::handler_work<boost::asio::any_completion_handler<void (boost::system::error_code)>, boost::asio::executor>' requested here
[build]   channel_operation::handler_work<Handler, IoExecutor> work_;
[build]                                                        ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_service.hpp:202:14: note: in instantiation of template class 'boost::asio::experimental::detail::channel_receive_op<boost::asio::experimental::detail::channel_payload<void (boost::system::error_code)>, boost::asio::any_completion_handler<void (boost::system::error_code)>, boost::asio::executor>' requested here
[build]     typename op::ptr p = { boost::asio::detail::addressof(handler),
[build]              ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/basic_channel.hpp:490:24: note: in instantiation of function template specialization 'boost::asio::experimental::detail::channel_service<boost::asio::detail::null_mutex>::async_receive<boost::asio::experimental::channel_traits<>, void (boost::system::error_code), boost::asio::any_completion_handler<void (boost::system::error_code)>, boost::asio::executor>' requested here
[build]       self_->service_->async_receive(self_->impl_,
[build]                        ^
[build] /opt/boost-1.84.0/include/boost/asio/async_result.hpp:273:5: note: in instantiation of function template specialization 'boost::asio::experimental::basic_channel<boost::asio::executor, boost::asio::experimental::channel_traits<>, void (boost::system::error_code)>::initiate_async_receive::operator()<boost::asio::any_completion_handler<void (boost::system::error_code)>>' requested here
[build]     static_cast<Initiation&&>(initiation)(
[build]     ^
[build] /opt/boost-1.84.0/include/boost/asio/async_result.hpp:570:65: note: in instantiation of function template specialization 'boost::asio::detail::completion_handler_async_result<boost::asio::any_completion_handler<void (boost::system::error_code)>, void (boost::system::error_code)>::initiate<boost::asio::experimental::basic_channel<boost::asio::executor, boost::asio::experimental::channel_traits<>, void (boost::system::error_code)>::initiate_async_receive, boost::asio::any_completion_handler<void (boost::system::error_code)>>' requested here
[build]   return async_result<decay_t<CompletionToken>, Signatures...>::initiate(
[build]                                                                 ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/basic_channel.hpp:120:12: note: in instantiation of function template specialization 'boost::asio::async_initiate<boost::asio::any_completion_handler<void (boost::system::error_code)>, void (boost::system::error_code), boost::asio::experimental::basic_channel<boost::asio::executor, boost::asio::experimental::channel_traits<>, void (boost::system::error_code)>::initiate_async_receive>' requested here
[build]     return async_initiate<CompletionToken, PayloadSignatures...>(
[build]            ^
[build] /opt/boost-1.84.0/include/boost/asio/experimental/basic_channel.hpp:414:18: note: in instantiation of function template specialization 'boost::asio::experimental::basic_channel<boost::asio::executor, boost::asio::experimental::channel_traits<>, void (boost::system::error_code)>::do_async_receive<void (boost::system::error_code), boost::asio::any_completion_handler<void (boost::system::error_code)>>' requested here
[build]     return this->do_async_receive(static_cast<payload_type*>(0),
[build]                  ^
[build] /home/ruben/workspace/mysql/private/test-programs/testground/main.cpp:12:10: note: in instantiation of function template specialization 'boost::asio::experimental::basic_channel<boost::asio::executor, boost::asio::experimental::channel_traits<>, void (boost::system::error_code)>::async_receive<boost::asio::any_completion_handler<void (boost::system::error_code)>>' requested here
[build]     chan.async_receive(asio::any_completion_handler<void(error_code)>([](...) {}));
[build]          ^
[build] In file included from /home/ruben/workspace/mysql/private/test-programs/testground/main.cpp:4:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/channel.hpp:23:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/basic_channel.hpp:24:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_service.hpp:25:
[build] In file included from /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_receive_op.hpp:23:
[build] /opt/boost-1.84.0/include/boost/asio/experimental/detail/channel_operation.hpp:127:17: error: field has incomplete type 'executor_type' (aka 'void')
[build]   executor_type executor_;
[build]                 ^
``