diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index f8fe9c0986f..3cad070aeeb 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -1608,9 +1608,11 @@ template ::value, int> = object cast(T &&value, return_value_policy policy = return_value_policy::automatic_reference, handle parent = handle()) { if (policy == return_value_policy::automatic) - policy = std::is_pointer::value ? return_value_policy::take_ownership : return_value_policy::copy; + policy = std::is_pointer::value ? return_value_policy::take_ownership : + std::is_lvalue_reference::value ? return_value_policy::copy : return_value_policy::move; else if (policy == return_value_policy::automatic_reference) - policy = std::is_pointer::value ? return_value_policy::reference : return_value_policy::copy; + policy = std::is_pointer::value ? return_value_policy::reference : + std::is_lvalue_reference::value ? return_value_policy::copy : return_value_policy::move; return reinterpret_steal(detail::make_caster::cast(std::forward(value), policy, parent)); }