From f948c9cbe57552f2a2b1306235ba578584b1d2c0 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sun, 27 May 2018 19:05:43 -0700 Subject: [PATCH] Fix move-only arguments in bind_handler --- CHANGELOG.md | 1 + include/boost/beast/core/detail/bind_handler.hpp | 8 ++++---- test/beast/core/bind_handler.cpp | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f066cd0d..5706d93b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 172: * Tidy up websocket stream javadocs +* Fix move-only arguments in bind_handler -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/detail/bind_handler.hpp b/include/boost/beast/core/detail/bind_handler.hpp index 48046df9..8bacc921 100644 --- a/include/boost/beast/core/detail/bind_handler.hpp +++ b/include/boost/beast/core/detail/bind_handler.hpp @@ -51,10 +51,10 @@ class bound_handler boost::is_placeholder::type>::value == 0, Arg&&>::type - extract(Arg&& arg, Vals& vals) + extract(Arg&& arg, Vals&& vals) { boost::ignore_unused(vals); - return arg; + return std::forward(arg); } template @@ -101,7 +101,7 @@ class bound_handler index_sequence) { boost::ignore_unused(args); - h(std::get(args)...); + h(std::get(std::move(args))...); } template< @@ -118,7 +118,7 @@ class bound_handler { boost::ignore_unused(args); boost::ignore_unused(vals); - h(extract(std::get(args), + h(extract(std::get(std::move(args)), std::forward(vals))...); } diff --git a/test/beast/core/bind_handler.cpp b/test/beast/core/bind_handler.cpp index 54b223e0..1d93195b 100644 --- a/test/beast/core/bind_handler.cpp +++ b/test/beast/core/bind_handler.cpp @@ -81,6 +81,21 @@ public: s.wrap(copyable_handler{})); } + struct move_only + { + move_only() = default; + move_only(move_only&&) = default; + move_only(move_only const&) = delete; + }; + + void + testMoveOnly() + { + bind_handler([](move_only){}, move_only{})(); + bind_handler([](move_only){}, std::placeholders::_1)(move_only{}); + bind_handler([](move_only, move_only){}, move_only{}, std::placeholders::_1)(move_only{}); + } + void run() override { @@ -90,6 +105,7 @@ public: f(); testPlaceholders(); testAsioHandlerInvoke(); + testMoveOnly(); } };