From 501135fa769ca5ad73ca81315da509bffa5adeb9 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Fri, 7 Apr 2017 11:11:14 -0400 Subject: [PATCH] Add static_assert to holder casters The holder casters assume but don't check that a `holder`'s `type` is really a `type_caster_base`; this adds a static_assert to make sure this is really the case, to turn things like `std::shared_ptr` into a compilation failure. Fixes #785 --- include/pybind11/cast.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 95a9a4a7e..b99620393 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -902,6 +902,8 @@ template struct copyable_holder_caster : public type_caster_base { public: using base = type_caster_base; + static_assert(std::is_base_of>::value, + "Holder classes are only supported for custom types"); using base::base; using base::cast; using base::typeinfo; @@ -1018,6 +1020,9 @@ class type_caster> : public copyable_holder_caster struct move_only_holder_caster { + static_assert(std::is_base_of, type_caster>::value, + "Holder classes are only supported for custom types"); + static handle cast(holder_type &&src, return_value_policy, handle) { auto *ptr = holder_helper::get(src); return type_caster_base::cast_holder(ptr, &src);