From 231bd84fa03c86dfbc8e605b47c2dfaf0e247d0e Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sat, 30 Jan 2021 00:42:36 -0800 Subject: [PATCH] Moving up is_smart_holder_type_caster, to also use in cast_is_temporary_value_reference. --- include/pybind11/cast.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 44764e3df..b4d809784 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1717,6 +1717,13 @@ template struct move_if_unreferenced::value>> : std::true_type {}; template using move_never = none_of, move_if_unreferenced>; +template +struct is_smart_holder_type_caster : std::false_type {}; +template +struct is_smart_holder_type_caster< + T, + enable_if_t::is_smart_holder_type_caster::value, void>> : std::true_type {}; + // Detect whether returning a `type` from a cast on type's type_caster is going to result in a // reference or pointer to a local variable of the type_caster. Basically, only // non-reference/pointer `type`s and reference/pointers from a type_caster_generic are safe; @@ -1724,7 +1731,8 @@ template using move_never = none_of, move_if_unrefer template using cast_is_temporary_value_reference = bool_constant< (std::is_reference::value || std::is_pointer::value) && !std::is_base_of>::value && - !std::is_same, void>::value + !std::is_same, void>::value && + !is_smart_holder_type_caster>::value >; // When a value returned from a C++ function is being cast back to Python, we almost always want to @@ -2261,13 +2269,6 @@ object object_api::call(Args &&...args) const { return operator()(std::forward(args)...); } -template -struct is_smart_holder_type_caster : std::false_type {}; -template -struct is_smart_holder_type_caster< - T, - enable_if_t::is_smart_holder_type_caster::value, void>> : std::true_type {}; - PYBIND11_NAMESPACE_END(detail)