Add additional check to be more compliant with other casters

This commit is contained in:
fatvlady 2020-06-29 20:52:35 +03:00 committed by Wenzel Jakob
parent 8c06b95492
commit f99ff736c2

View File

@ -266,8 +266,9 @@ template<typename T> struct optional_caster {
static handle cast(T_ &&src, return_value_policy policy, handle parent) { static handle cast(T_ &&src, return_value_policy policy, handle parent) {
if (!src) if (!src)
return none().inc_ref(); return none().inc_ref();
using dereference_type = decltype(*std::forward<T_>(src)); if (!std::is_lvalue_reference<T>::value) {
policy = return_value_policy_override<dereference_type>::policy(policy); policy = return_value_policy_override<T>::policy(policy);
}
return value_conv::cast(*std::forward<T_>(src), policy, parent); return value_conv::cast(*std::forward<T_>(src), policy, parent);
} }