mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Use std::addressof to obtain holder address instead of operator&
This commit is contained in:
committed by
Jason Rhinelander
parent
9b02856293
commit
e3cb2a674a
@@ -203,6 +203,50 @@ def test_move_only_holder():
|
||||
assert stats.alive() == 0
|
||||
|
||||
|
||||
def test_holder_with_addressof_operator():
|
||||
# this test must not throw exception from c++
|
||||
a = m.TypeForHolderWithAddressOf.make()
|
||||
a.print_object_1()
|
||||
a.print_object_2()
|
||||
a.print_object_3()
|
||||
a.print_object_4()
|
||||
|
||||
stats = ConstructorStats.get(m.TypeForHolderWithAddressOf)
|
||||
assert stats.alive() == 1
|
||||
|
||||
np = m.TypeForHolderWithAddressOf.make()
|
||||
assert stats.alive() == 2
|
||||
del a
|
||||
assert stats.alive() == 1
|
||||
del np
|
||||
assert stats.alive() == 0
|
||||
|
||||
b = m.TypeForHolderWithAddressOf.make()
|
||||
c = b
|
||||
assert b.get() is c.get()
|
||||
assert stats.alive() == 1
|
||||
|
||||
del b
|
||||
assert stats.alive() == 1
|
||||
|
||||
del c
|
||||
assert stats.alive() == 0
|
||||
|
||||
|
||||
def test_move_only_holder_with_addressof_operator():
|
||||
a = m.TypeForMoveOnlyHolderWithAddressOf.make()
|
||||
a.print_object()
|
||||
|
||||
stats = ConstructorStats.get(m.TypeForMoveOnlyHolderWithAddressOf)
|
||||
assert stats.alive() == 1
|
||||
|
||||
a.value = 42
|
||||
assert a.value == 42
|
||||
|
||||
del a
|
||||
assert stats.alive() == 0
|
||||
|
||||
|
||||
def test_smart_ptr_from_default():
|
||||
instance = m.HeldByDefaultHolder()
|
||||
with pytest.raises(RuntimeError) as excinfo:
|
||||
|
||||
Reference in New Issue
Block a user