1

After update boost libraries from 1.71 up to 1.74, my code, which uses boost::asio::spawn(), does not compile with MSVC2019 (19.25.28612 for x64) with predefined macro BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT. AFAIK, this macro is supposed for backward compatibilty and I have to use this macro because I use boost::beast::saved_handler but it uses executor work guards which are not defined for proposed standard executors.

More than that my code successfully compiles with clang-11 (and defined BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT).

Here is a simple code example which fails to compile with MSVC2019 and Boost.Asio:1.74 but will compile with Boost.Asio:1.71 (of course, boost::asio::any_io_executor should be replaced back with boost::asio::executor):

#define BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>

int main()
{
  boost::asio::io_context ctx;
  boost::asio::any_io_executor executor = ctx.get_executor();
  boost::asio::spawn(executor, [](auto yield){});
  return 0;
}

with following output:

C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): error C2672: 'boost::asio::strand<Executor>::execute': no matching overloaded function found
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/impl/dispatch.hpp(57): note: see reference to function template instantiation 'void asio_execution_execute_fn::impl::operator ()<boost::asio::strand<Executor>,boost::asio::detail::spawn_helper<handler_type,function_type>&>(T &&,F) noexcept(false) const' being compiled
        with
        [
            Executor=boost::asio::executor,
            T=boost::asio::strand<boost::asio::executor>,
            F=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(151): note: see reference to function template instantiation 'void boost::asio::detail::initiate_dispatch::operator ()<boost::asio::detail::spawn_helper<handler_type,function_type>&>(CompletionHandler,void *) const' being compiled
        with
        [
            CompletionHandler=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(363): note: see reference to function template instantiation 'boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::return_type boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::initiate<Initiation,boost::asio::detail::spawn_helper<handler_type,function_type>&,>(Initiation &&,RawCompletionToken)' being compiled
        with
        [
            Signature=void (void),
            Initiation=boost::asio::detail::initiate_dispatch,
            RawCompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/async_result.hpp(364): note: see reference to function template instantiation 'boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::return_type boost::asio::async_result<boost::asio::detail::spawn_helper<handler_type,function_type>,Signature>::initiate<Initiation,boost::asio::detail::spawn_helper<handler_type,function_type>&,>(Initiation &&,RawCompletionToken)' being compiled
        with
        [
            Signature=void (void),
            Initiation=boost::asio::detail::initiate_dispatch,
            RawCompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/impl/dispatch.hpp(212): note: see reference to function template instantiation 'void boost::asio::async_initiate<CompletionToken,void(void),boost::asio::detail::initiate_dispatch,>(Initiation &&,CompletionToken)' being compiled
        with
        [
            CompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &,
            Initiation=boost::asio::detail::initiate_dispatch
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(452): note: see reference to function template instantiation 'void boost::asio::dispatch<boost::asio::detail::spawn_helper<handler_type,function_type>&>(CompletionToken)' being compiled
        with
        [
            CompletionToken=boost::asio::detail::spawn_helper<handler_type,function_type> &
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(493): note: see reference to function template instantiation 'void boost::asio::spawn<boost::asio::executor_binder<void (__cdecl *)(void),boost::asio::strand<Executor>>,Function>(Handler &&,Function &&,const boost::coroutines::attributes &,void *)' being compiled
        with
        [
            Executor=boost::asio::executor,
            Function=main::<lambda_c142a977195366454fba7e579637857b>,
            Handler=boost::asio::executor_binder<void (__cdecl *)(void),boost::asio::strand<boost::asio::executor>>
        ]
C:\local\boost_1_74_0\boost/asio/impl/spawn.hpp(483): note: see reference to function template instantiation 'void boost::asio::spawn<Function,Executor>(const boost::asio::strand<Executor> &,Function &&,const boost::coroutines::attributes &)' being compiled
        with
        [
            Function=main::<lambda_c142a977195366454fba7e579637857b>,
            Executor=boost::asio::executor
        ]
C:\Users\Artem Suleimanov\CLionProjects\test\main.cpp(10): note: see reference to function template instantiation 'void boost::asio::spawn<main::<lambda_c142a977195366454fba7e579637857b>,boost::asio::executor>(const Executor &,Function &&,const boost::coroutines::attributes &,void *)' being compiled
        with
        [
            Executor=boost::asio::executor,
            Function=main::<lambda_c142a977195366454fba7e579637857b>
        ]
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): error C2893: Failed to specialize function template 'enable_if<boost::asio::execution::can_execute<const Executor&,Function>::value,void>::type boost::asio::strand<Executor>::execute(Function &&) const'
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/strand.hpp(276): note: see declaration of 'boost::asio::strand<Executor>::execute'
        with
        [
            Executor=boost::asio::executor
        ]
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): note: With the following template arguments:
C:\local\boost_1_74_0\boost/asio/execution/execute.hpp(192): note: 'Function=boost::asio::detail::spawn_helper<handler_type,function_type> &'

Is that a compiler/boost bug or I am doing something wrong?

2
  • I think it's a platform specific problem indeed. I can't really tell much because online compilers don't seem to have 1.74.0 godbolt.org/z/sPsa8Y By the way. it looks like you used executor, not any_io_executor for the message, even though it was 1.74. Not sure whether that is intentional/matters
    – sehe
    Dec 2, 2020 at 21:29
  • When BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT is on, executor == any_io_executor, it's just a typedef.
    – Nevermore
    Dec 3, 2020 at 12:38

1 Answer 1

2

Seems that this issue was fixed. I applied the patch and code now compiles by MSVC2019.

THe release notes entry for this fix:

  • Fixed strand<> adaptation of Networking TS executors when targeting older C++ versions or less conformant compilers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.