boost::asio::spawn 被 BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT 破坏了?
boost::asio::spawn is broken with BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT?
将 boost 库从 1.71 更新到 1.74 后,我使用 boost::asio::spawn()
的代码无法使用带有预定义宏 BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
的 MSVC2019(x64 为 19.25.28612)进行编译。 AFAIK,这个宏应该是为了向后兼容,我必须使用这个宏,因为我使用 boost::beast::saved_handler
但它使用未为提议的标准执行程序定义的执行程序工作守卫。
不止于此,我的代码使用 clang-11 成功编译(并定义了 BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
)。
这是一个简单的代码示例,无法使用 MSVC2019 和 Boost.Asio:1.74 进行编译,但可以使用 Boost.Asio:1.71 进行编译(当然,boost::asio::any_io_executor
应替换回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;
}
具有以下输出:
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> &'
这是 compiler/boost 错误还是我做错了什么?
这个问题似乎是 fixed。我应用了补丁,代码现在由 MSVC2019 编译。
此修复的发行说明条目:
- 修复了
strand<>
针对较旧的网络 TS 执行程序的适应
C++ 版本或不太符合的编译器。
将 boost 库从 1.71 更新到 1.74 后,我使用 boost::asio::spawn()
的代码无法使用带有预定义宏 BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
的 MSVC2019(x64 为 19.25.28612)进行编译。 AFAIK,这个宏应该是为了向后兼容,我必须使用这个宏,因为我使用 boost::beast::saved_handler
但它使用未为提议的标准执行程序定义的执行程序工作守卫。
不止于此,我的代码使用 clang-11 成功编译(并定义了 BOOST_ASIO_USE_TS_EXECUTOR_AS_DEFAULT
)。
这是一个简单的代码示例,无法使用 MSVC2019 和 Boost.Asio:1.74 进行编译,但可以使用 Boost.Asio:1.71 进行编译(当然,boost::asio::any_io_executor
应替换回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;
}
具有以下输出:
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> &'
这是 compiler/boost 错误还是我做错了什么?
这个问题似乎是 fixed。我应用了补丁,代码现在由 MSVC2019 编译。
此修复的发行说明条目:
- 修复了
strand<>
针对较旧的网络 TS 执行程序的适应 C++ 版本或不太符合的编译器。