mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +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:
@@ -211,3 +211,12 @@ def test_move_only_holder():
|
||||
assert stats.alive() == 1
|
||||
del a
|
||||
assert stats.alive() == 0
|
||||
|
||||
|
||||
def test_smart_ptr_from_default():
|
||||
from pybind11_tests.smart_ptr import HeldByDefaultHolder
|
||||
|
||||
instance = HeldByDefaultHolder()
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
HeldByDefaultHolder.load_shared_ptr(instance)
|
||||
assert "Unable to load a custom holder type from a default-holder instance" in str(excinfo)
|
||||
|
||||
Reference in New Issue
Block a user