Skip to content

Commit 81acf73

Browse files
committed
fixup! Add (failing) roundtrip test for const unique_ptr reference
1 parent 23e03d5 commit 81acf73

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

tests/test_class_sh_basic.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,18 @@ def test_unique_ptr_consumer_roundtrip(pass_f, rtrn_f, moved_out, moved_in):
158158
)
159159
@pytest.mark.parametrize(
160160
"pass_f",
161-
[m.consumer.pass_uq_cref, m.consumer.pass_cptr, m.consumer.pass_cref],
161+
[
162+
# This fails with: ValueError: Cannot disown non-owning holder (loaded_as_unique_ptr).
163+
#
164+
# smart_holder_type_caster_load<T>::loaded_as_unique_ptr() attempts to pass
165+
# the not-owned cref as a new unique_ptr, which would eventually destroy the object,
166+
# and is thus (correctly) suppressed.
167+
# To fix this, smart_holder would need to store the (original) unique_ptr reference,
168+
# e.g. using a union of unique_ptr + shared_ptr.
169+
pytest.param(m.consumer.pass_uq_cref, marks=pytest.mark.xfail),
170+
m.consumer.pass_cptr,
171+
m.consumer.pass_cref,
172+
],
162173
)
163174
def test_unique_ptr_cref_consumer_roundtrip(rtrn_f, pass_f):
164175
c = m.consumer()
@@ -168,16 +179,6 @@ def test_unique_ptr_cref_consumer_roundtrip(rtrn_f, pass_f):
168179

169180
c.pass_uq_valu(passenger) # moves passenger to C++ (checked above)
170181

171-
if pass_f == m.consumer.pass_uq_cref:
172-
# This fails with: ValueError: Cannot disown non-owning holder (loaded_as_unique_ptr).
173-
#
174-
# smart_holder_type_caster_load<T>::loaded_as_unique_ptr() attempts to pass
175-
# the not-owned cref as a new unique_ptr, which would eventually destroy the object,
176-
# and is thus (correctly) suppressed.
177-
# To fix this, smart_holder would need to store the (original) unique_ptr reference,
178-
# e.g. using a union of unique_ptr + shared_ptr.
179-
pytest.xfail()
180-
181182
for _ in range(10):
182183
cref = rtrn_f(c) # fetches const reference, should keep-alive parent c
183184
assert pass_f(c, cref) == mtxt_orig

0 commit comments

Comments
 (0)