SH, improve error message from shared_ptr cast policy check

This commit is contained in:
Jakob Lykke Andersen 2021-06-19 16:43:12 +02:00 committed by Ralf W. Grosse-Kunstleve
parent be60fc52a4
commit 7312e624b2

View File

@ -627,15 +627,16 @@ struct smart_holder_type_caster<std::shared_ptr<T>> : smart_holder_type_caster_l
static constexpr auto name = _<std::shared_ptr<T>>(); static constexpr auto name = _<std::shared_ptr<T>>();
static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) { static handle cast(const std::shared_ptr<T> &src, return_value_policy policy, handle parent) {
if (policy != return_value_policy::automatic switch (policy) {
&& policy != return_value_policy::automatic_reference case return_value_policy::automatic: break;
// (but not take_ownership) case return_value_policy::automatic_reference: break;
&& policy != return_value_policy::copy case return_value_policy::take_ownership:
&& policy != return_value_policy::move throw cast_error("Invalid return_value_policy for shared_ptr (take_ownership).");
// (but not reference) case return_value_policy::copy: break;
&& policy != return_value_policy::reference_internal) { case return_value_policy::move: break;
// SMART_HOLDER_WIP: IMPROVABLE: Error message. case return_value_policy::reference:
throw cast_error("Invalid return_value_policy for shared_ptr."); throw cast_error("Invalid return_value_policy for shared_ptr (reference).");
case return_value_policy::reference_internal: break;
} }
if (!src) if (!src)
return none().release(); return none().release();