diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index f13f9c5b7..8a9a40340 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1623,6 +1623,23 @@ struct property_cpp_function { } }; +PYBIND11_NAMESPACE_BEGIN(detail) + +template +struct both_t_and_d_use_type_caster_base : std::false_type {}; + +// `T` is assumed to be equivalent to `intrinsic_t`. +// `D` is not. +template +struct both_t_and_d_use_type_caster_base< + T, + D, + enable_if_t, type_caster>, + std::is_base_of>, make_caster>>::value>> + : std::true_type {}; + +PYBIND11_NAMESPACE_END(detail) + // BAKEIN_WIP: Rewrite comment. // smart_holder specializations for raw pointer members. // WARNING: Like the classic implementation, this implementation can lead to dangling pointers. @@ -1634,10 +1651,8 @@ template struct property_cpp_function< T, D, - detail::enable_if_t< - detail::all_of>, - std::is_base_of>, - std::is_pointer>::value>> { + detail::enable_if_t, + detail::both_t_and_d_use_type_caster_base>::value>> { using drp = typename std::remove_pointer::type; @@ -1679,16 +1694,14 @@ struct property_cpp_function< // https://github.com/google/clif/blob/c371a6d4b28d25d53a16e6d2a6d97305fb1be25a/clif/python/instance.h#L233 // This prevents disowning of the Python object owning the member. template -struct property_cpp_function< - T, - D, - detail::enable_if_t< - detail::all_of>, - std::is_base_of>, - detail::none_of, - std::is_array, - detail::is_instantiation, - detail::is_instantiation>>::value>> { +struct property_cpp_function, + std::is_array, + detail::is_instantiation, + detail::is_instantiation>, + detail::both_t_and_d_use_type_caster_base>::value>> { template = 0> static cpp_function readonly(PM pm, const handle &hdl) { @@ -1742,11 +1755,9 @@ template struct property_cpp_function< T, D, - detail::enable_if_t< - detail::all_of>, - detail::is_instantiation, - std::is_base_of>>::value>> { + detail::enable_if_t, + detail::both_t_and_d_use_type_caster_base>::value>> { template = 0> static cpp_function readonly(PM, const handle &) {