From 7312e624b233c5b072e031543037e32a1b8219fb Mon Sep 17 00:00:00 2001 From: Jakob Lykke Andersen Date: Sat, 19 Jun 2021 16:43:12 +0200 Subject: [PATCH] SH, improve error message from shared_ptr cast policy check --- .../detail/smart_holder_type_casters.h | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/include/pybind11/detail/smart_holder_type_casters.h b/include/pybind11/detail/smart_holder_type_casters.h index 30709b0e8..d6d62016c 100644 --- a/include/pybind11/detail/smart_holder_type_casters.h +++ b/include/pybind11/detail/smart_holder_type_casters.h @@ -627,15 +627,16 @@ struct smart_holder_type_caster> : smart_holder_type_caster_l static constexpr auto name = _>(); static handle cast(const std::shared_ptr &src, return_value_policy policy, handle parent) { - if (policy != return_value_policy::automatic - && policy != return_value_policy::automatic_reference - // (but not take_ownership) - && policy != return_value_policy::copy - && policy != return_value_policy::move - // (but not reference) - && policy != return_value_policy::reference_internal) { - // SMART_HOLDER_WIP: IMPROVABLE: Error message. - throw cast_error("Invalid return_value_policy for shared_ptr."); + switch (policy) { + case return_value_policy::automatic: break; + case return_value_policy::automatic_reference: break; + case return_value_policy::take_ownership: + throw cast_error("Invalid return_value_policy for shared_ptr (take_ownership)."); + case return_value_policy::copy: break; + case return_value_policy::move: break; + case return_value_policy::reference: + throw cast_error("Invalid return_value_policy for shared_ptr (reference)."); + case return_value_policy::reference_internal: break; } if (!src) return none().release();