Skip to content

Commit

Permalink
inplace_function: Add a missing std::forward.
Browse files Browse the repository at this point in the history
The missing `forward` around these `args...` was preventing the noexcept
specifier from compiling for wrapped types that took non-copyable argument
types (such as `unique_ptr`).

Fixes #154.
  • Loading branch information
Quuxplusone committed Mar 16, 2019
1 parent c0d78e8 commit cb66020
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions SG14/inplace_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ template<typename R, typename... Args> struct vtable

template<typename C> explicit constexpr vtable(wrapper<C>) noexcept :
invoke_ptr{ [](storage_ptr_t storage_ptr, Args&&... args)
noexcept(noexcept(std::declval<C>()(args...))) -> R
noexcept(noexcept(std::declval<C>()(static_cast<Args&&>(args)...))) -> R
{ return (*static_cast<C*>(storage_ptr))(
std::forward<Args>(args)...
static_cast<Args&&>(args)...
); }
},
copy_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr)
Expand Down
15 changes: 15 additions & 0 deletions SG14_test/inplace_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,20 @@ struct test_bug_32072 {
static_assert(std::is_copy_constructible<test_bug_32072>::value, "");
static_assert(std::is_nothrow_move_constructible<test_bug_32072>::value, "");

static void RvalueRefParameter()
{
stdext::inplace_function<void(std::unique_ptr<int>&&)> f;
f = [](std::unique_ptr<int>) {};
f = [](std::unique_ptr<int>&&) {};
f = [](const std::unique_ptr<int>&) {};
f(std::make_unique<int>(42));
stdext::inplace_function<void(std::unique_ptr<int>)> g;
g = [](std::unique_ptr<int>) {};
g = [](std::unique_ptr<int>&&) {};
g = [](const std::unique_ptr<int>&) {};
g(std::make_unique<int>(42));
}

void sg14_test::inplace_function_test()
{
// first set of tests (from Optiver)
Expand All @@ -427,6 +441,7 @@ void sg14_test::inplace_function_test()
ContainingStdFunction();
SimilarTypeCopy();
FunctorDestruction();
RvalueRefParameter();

// second set of tests
using IPF = stdext::inplace_function<void(int)>;
Expand Down

0 comments on commit cb66020

Please sign in to comment.