Skip to content

Commit 25b130d

Browse files
committed
Fixed wrong selection of return_value_policy::automatic/automatic_reference for pointers in py::cast with universal reference
1 parent f496ee3 commit 25b130d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

include/pybind11/cast.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,11 +1669,12 @@ T cast(const handle &handle) { return T(reinterpret_borrow<object>(handle)); }
16691669
template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> = 0>
16701670
object cast(T &&value, return_value_policy policy = return_value_policy::automatic_reference,
16711671
handle parent = handle()) {
1672+
using no_ref_T = typename std::remove_reference<T>::type;
16721673
if (policy == return_value_policy::automatic)
1673-
policy = std::is_pointer<T>::value ? return_value_policy::take_ownership :
1674+
policy = std::is_pointer<no_ref_T>::value ? return_value_policy::take_ownership :
16741675
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16751676
else if (policy == return_value_policy::automatic_reference)
1676-
policy = std::is_pointer<T>::value ? return_value_policy::reference :
1677+
policy = std::is_pointer<no_ref_T>::value ? return_value_policy::reference :
16771678
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16781679
return reinterpret_steal<object>(detail::make_caster<T>::cast(std::forward<T>(value), policy, parent));
16791680
}

0 commit comments

Comments
 (0)