Skip to content

Commit 396cde5

Browse files
committed
Fix copying/moving in test_virtual_functions
Don't enforce moving by passing the caster as an rvalue to cast_op().
1 parent 445d598 commit 396cde5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

include/pybind11/cast.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,6 @@ template <typename T, typename SFINAE> type_caster<T, SFINAE> &load_type(type_ca
855855
}
856856
return conv;
857857
}
858-
// Wrapper around the above that also constructs and returns a type_caster
859-
template <typename T> make_caster<T> load_type(const handle &handle) {
860-
make_caster<T> conv;
861-
load_type(conv, handle);
862-
return conv;
863-
}
864858

865859
PYBIND11_NAMESPACE_END(detail)
866860

@@ -870,7 +864,9 @@ T cast(const handle &handle) {
870864
using namespace detail;
871865
static_assert(!cast_is_temporary_value_reference<T>::value,
872866
"Unable to cast type to reference: value is local to type caster");
873-
return cast_op<T>(load_type<T>(handle));
867+
make_caster<T> conv;
868+
load_type(conv, handle);
869+
return cast_op<T>(conv);
874870
}
875871

876872
// pytype -> pytype (calls converting constructor)
@@ -906,7 +902,9 @@ detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) {
906902
#endif
907903

908904
// Move into a temporary and return that, because the reference may be a local value of `conv`
909-
T ret = std::move(detail::load_type<T>(obj).operator T&());
905+
detail::make_caster<T> conv;
906+
load_type(conv, obj);
907+
T ret = std::move(conv.operator T &());
910908
return ret;
911909
}
912910

0 commit comments

Comments
 (0)