Skip to content

Commit

Permalink
Add a missing & to the new SFINAE constraint on callability.
Browse files Browse the repository at this point in the history
When we actually call the captured `C`, we call it as a non-const lvalue;
so that's what we should be testing here.
  • Loading branch information
Quuxplusone committed May 1, 2019
1 parent a53e9e6 commit 98591c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion SG14/inplace_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class inplace_function<R(Args...), Capacity, Alignment>
typename C = std::decay_t<T>,
typename = std::enable_if_t<
!inplace_function_detail::is_inplace_function<C>::value
&& inplace_function_detail::is_invocable_r<R, C, Args...>::value
&& inplace_function_detail::is_invocable_r<R, C&, Args...>::value
>
>
inplace_function(T&& closure)
Expand Down
21 changes: 21 additions & 0 deletions SG14_test/inplace_function_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,26 @@ static void test_is_convertible()
static_assert(std::is_convertible<int(*&&)(), stdext::inplace_function<int()>>::value, "");
}

static void test_convertibility_with_qualified_call_operators()
{
struct Callable { void operator()() {} };
struct LvalueOnlyCallable { void operator()() & {} };
struct RvalueOnlyCallable { void operator()() && {} };
struct ConstCallable { void operator()() const {} };
struct ConstOnlyCallable { void operator()() const {} void operator()() = delete; };
struct NonconstOnlyCallable { void operator()() {} void operator()() const = delete; };
struct LvalueConstCallable { void operator()() const & {} };
struct NoexceptCallable { void operator()() noexcept {} };
static_assert(std::is_convertible<Callable, stdext::inplace_function<void()>>::value, "");
static_assert(std::is_convertible<LvalueOnlyCallable, stdext::inplace_function<void()>>::value, "");
static_assert(!std::is_convertible<RvalueOnlyCallable, stdext::inplace_function<void()>>::value, "");
static_assert(std::is_convertible<ConstCallable, stdext::inplace_function<void()>>::value, "");
static_assert(!std::is_convertible<ConstOnlyCallable, stdext::inplace_function<void()>>::value, "");
static_assert(std::is_convertible<NonconstOnlyCallable, stdext::inplace_function<void()>>::value, "");
static_assert(std::is_convertible<LvalueConstCallable, stdext::inplace_function<void()>>::value, "");
static_assert(std::is_convertible<NoexceptCallable, stdext::inplace_function<void()>>::value, "");
}

namespace {
struct InstrumentedCopyConstructor {
static int copies;
Expand Down Expand Up @@ -673,6 +693,7 @@ void sg14_test::inplace_function_test()
test_move_construction_is_noexcept();
test_move_construction_from_smaller_buffer_is_noexcept();
test_is_convertible();
test_convertibility_with_qualified_call_operators();
test_return_by_move();
test_is_invocable();
test_overloading();
Expand Down

0 comments on commit 98591c4

Please sign in to comment.