diff --git a/function_ref.hpp b/function_ref.hpp index 36d2a55..a177e20 100644 --- a/function_ref.hpp +++ b/function_ref.hpp @@ -115,7 +115,7 @@ struct is_invocable_r_impl : std::false_type {}; template struct is_invocable_r_impl< - typename std::is_same, R>::type, R, F, Args...> + typename std::is_convertible, R>::type, R, F, Args...> : std::true_type {}; template @@ -152,7 +152,7 @@ template class function_ref { detail::is_invocable_r::value> * = nullptr> TL_FUNCTION_REF_11_CONSTEXPR function_ref(F &&f) noexcept : obj_(const_cast(reinterpret_cast(std::addressof(f)))) { - callback_ = [](void *obj, Args... args) { + callback_ = [](void *obj, Args... args) -> R { return detail::invoke( *reinterpret_cast::type>(obj), std::forward(args)...); diff --git a/tests/issues.cpp b/tests/issues.cpp index 098324f..6098839 100644 --- a/tests/issues.cpp +++ b/tests/issues.cpp @@ -5,4 +5,18 @@ TEST_CASE("Issue #2") { const auto lam = [](int ) {}; tl::function_ref ref = lam; (void)ref; +} + +struct Fruit {}; +struct Apple : Fruit {}; + +Apple* getApple() { return nullptr; } + +tl::function_ref bar() +{ + return getApple; +} + +TEST_CASE("Issue #9") { + REQUIRE(bar()() == nullptr); } \ No newline at end of file