mirror of
https://github.com/pybind/pybind11.git
synced 2026-04-19 14:29:11 +00:00
Throw an exception when attempting to load an incompatible holder
Instead of a segfault. Fixes #751. This covers the case of loading a custom holder from a default-holder instance. Attempting to load one custom holder from a different custom holder (i.e. not `std::unique_ptr`) yields undefined behavior, just as #588 established for inheritance.
This commit is contained in:
@@ -265,4 +265,10 @@ test_initializer smart_ptr_and_references([](py::module &pm) {
|
||||
|
||||
py::class_<C, CustomUniquePtr<C>>(m, "TypeWithMoveOnlyHolder")
|
||||
.def_static("make", []() { return CustomUniquePtr<C>(new C); });
|
||||
|
||||
struct HeldByDefaultHolder { };
|
||||
|
||||
py::class_<HeldByDefaultHolder>(m, "HeldByDefaultHolder")
|
||||
.def(py::init<>())
|
||||
.def_static("load_shared_ptr", [](std::shared_ptr<HeldByDefaultHolder>) {});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user