mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 09:46:10 +00:00
don't try to cast 'None' into a C++ lvalue reference
This commit is contained in:
@@ -225,6 +225,8 @@ using cast_op_type = typename std::conditional<std::is_pointer<typename std::rem
|
||||
typename std::add_pointer<typename intrinsic_type<T>::type>::type,
|
||||
typename std::add_lvalue_reference<typename intrinsic_type<T>::type>::type>::type;
|
||||
|
||||
/// Thrown then trying to cast a null pointer into a reference argument
|
||||
class invalid_reference_cast : public std::exception { };
|
||||
|
||||
/// Generic type caster for objects stored on the heap
|
||||
template <typename type> class type_caster_base : public type_caster_generic {
|
||||
@@ -254,7 +256,7 @@ public:
|
||||
template <typename T> using cast_op_type = pybind11::detail::cast_op_type<T>;
|
||||
|
||||
operator type*() { return (type *) value; }
|
||||
operator type&() { return *((type *) value); }
|
||||
operator type&() { if (!value) throw invalid_reference_cast(); return *((type *) value); }
|
||||
|
||||
protected:
|
||||
typedef void *(*Constructor)(const void *stream);
|
||||
|
||||
@@ -409,8 +409,13 @@ protected:
|
||||
}
|
||||
}
|
||||
}
|
||||
if (kwargs_consumed == nkwargs)
|
||||
result = it->impl(it, args_, parent);
|
||||
|
||||
try {
|
||||
if (kwargs_consumed == nkwargs)
|
||||
result = it->impl(it, args_, parent);
|
||||
} catch (detail::invalid_reference_cast &) {
|
||||
result = PYBIND11_TRY_NEXT_OVERLOAD;
|
||||
}
|
||||
|
||||
if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD)
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user