diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 32f8d294a..77da13362 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -266,7 +266,8 @@ template struct optional_caster { static handle cast(T_ &&src, return_value_policy policy, handle parent) { if (!src) return none().inc_ref(); - policy = return_value_policy_override::policy(policy); + using dereference_type = decltype(*std::forward(src)); + policy = return_value_policy_override::policy(policy); return value_conv::cast(*std::forward(src), policy, parent); }