diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index bd0ee273..5689d5a3 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -950,6 +950,9 @@ public: static_assert(detail::all_of...>::value, "Unknown/invalid class_ template parameters provided"); + static_assert(!has_alias || std::is_polymorphic::value, + "Cannot use an alias class with a non-polymorphic type"); + PYBIND11_OBJECT(class_, generic_type, PyType_Check) template diff --git a/tests/test_class.cpp b/tests/test_class.cpp index 5860b741..670949f8 100644 --- a/tests/test_class.cpp +++ b/tests/test_class.cpp @@ -231,7 +231,7 @@ TEST_SUBMODULE(class_, m) { bind_local(m, "LocalExternal", py::module_local()); } -template class BreaksBase {}; +template class BreaksBase { public: virtual ~BreaksBase() = default; }; template class BreaksTramp : public BreaksBase {}; // These should all compile just fine: typedef py::class_, std::unique_ptr>, BreaksTramp<1>> DoesntBreak1;