mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-03 22:14:33 +08:00
Add static_assert to holder casters
The holder casters assume but don't check that a `holder<type>`'s `type` is really a `type_caster_base<type>`; this adds a static_assert to make sure this is really the case, to turn things like `std::shared_ptr<array>` into a compilation failure. Fixes #785
This commit is contained in:
parent
d994db2da0
commit
501135fa76
@ -902,6 +902,8 @@ template <typename type, typename holder_type>
|
|||||||
struct copyable_holder_caster : public type_caster_base<type> {
|
struct copyable_holder_caster : public type_caster_base<type> {
|
||||||
public:
|
public:
|
||||||
using base = type_caster_base<type>;
|
using base = type_caster_base<type>;
|
||||||
|
static_assert(std::is_base_of<base, type_caster<type>>::value,
|
||||||
|
"Holder classes are only supported for custom types");
|
||||||
using base::base;
|
using base::base;
|
||||||
using base::cast;
|
using base::cast;
|
||||||
using base::typeinfo;
|
using base::typeinfo;
|
||||||
@ -1018,6 +1020,9 @@ class type_caster<std::shared_ptr<T>> : public copyable_holder_caster<T, std::sh
|
|||||||
|
|
||||||
template <typename type, typename holder_type>
|
template <typename type, typename holder_type>
|
||||||
struct move_only_holder_caster {
|
struct move_only_holder_caster {
|
||||||
|
static_assert(std::is_base_of<type_caster_base<type>, type_caster<type>>::value,
|
||||||
|
"Holder classes are only supported for custom types");
|
||||||
|
|
||||||
static handle cast(holder_type &&src, return_value_policy, handle) {
|
static handle cast(holder_type &&src, return_value_policy, handle) {
|
||||||
auto *ptr = holder_helper<holder_type>::get(src);
|
auto *ptr = holder_helper<holder_type>::get(src);
|
||||||
return type_caster_base<type>::cast_holder(ptr, &src);
|
return type_caster_base<type>::cast_holder(ptr, &src);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user