diff --git a/SG14/inplace_function.h b/SG14/inplace_function.h index 59453966..00306de3 100644 --- a/SG14/inplace_function.h +++ b/SG14/inplace_function.h @@ -105,9 +105,11 @@ template struct vtable template explicit constexpr vtable(wrapper) noexcept : invoke_ptr{ [](storage_ptr_t storage_ptr, Args&&... args) -> R - { return (*static_cast(storage_ptr))( - static_cast(args)... - ); } + { + return static_cast((*static_cast(storage_ptr))( + static_cast(args)... + )); + } }, copy_ptr{ [](storage_ptr_t dst_ptr, storage_ptr_t src_ptr) -> void { ::new (dst_ptr) C{ (*static_cast(src_ptr)) }; } diff --git a/SG14_test/inplace_function_test.cpp b/SG14_test/inplace_function_test.cpp index 5fd228be..db52381d 100644 --- a/SG14_test/inplace_function_test.cpp +++ b/SG14_test/inplace_function_test.cpp @@ -467,6 +467,15 @@ static void test_convertibility_with_qualified_call_operators() static_assert(std::is_convertible>::value, ""); } +static void test_void_returning_function() +{ + auto lambda = []() { return 42; }; + static_assert(std::is_convertible>::value, ""); + stdext::inplace_function f = lambda; + f = lambda; + f(); +} + namespace { struct InstrumentedCopyConstructor { static int copies; @@ -694,6 +703,7 @@ void sg14_test::inplace_function_test() test_move_construction_from_smaller_buffer_is_noexcept(); test_is_convertible(); test_convertibility_with_qualified_call_operators(); + test_void_returning_function(); test_return_by_move(); test_is_invocable(); test_overloading();