mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 05:05:11 +00:00
Add a polymorphic static assert when using an alias
An alias can be used for two main purposes: to override virtual methods, and to add some extra data to a class needed for the pybind-wrapper. Both of these absolutely require that the wrapped class be polymorphic so that virtual dispatch and destruction, respectively, works.
This commit is contained in:
parent
b4bf5ed575
commit
42e5ddc541
@ -950,6 +950,9 @@ public:
|
||||
static_assert(detail::all_of<is_valid_class_option<options>...>::value,
|
||||
"Unknown/invalid class_ template parameters provided");
|
||||
|
||||
static_assert(!has_alias || std::is_polymorphic<type>::value,
|
||||
"Cannot use an alias class with a non-polymorphic type");
|
||||
|
||||
PYBIND11_OBJECT(class_, generic_type, PyType_Check)
|
||||
|
||||
template <typename... Extra>
|
||||
|
@ -231,7 +231,7 @@ TEST_SUBMODULE(class_, m) {
|
||||
bind_local<LocalExternal, 17>(m, "LocalExternal", py::module_local());
|
||||
}
|
||||
|
||||
template <int N> class BreaksBase {};
|
||||
template <int N> class BreaksBase { public: virtual ~BreaksBase() = default; };
|
||||
template <int N> class BreaksTramp : public BreaksBase<N> {};
|
||||
// These should all compile just fine:
|
||||
typedef py::class_<BreaksBase<1>, std::unique_ptr<BreaksBase<1>>, BreaksTramp<1>> DoesntBreak1;
|
||||
|
Loading…
Reference in New Issue
Block a user