Skip to content

Commit 8508572

Browse files
committed
Added test calling py::cast on an rvalue-reference of a move-only holder, in test_smart_ptr
1 parent dfa4d39 commit 8508572

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/test_smart_ptr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ TEST_SUBMODULE(smart_ptr, m) {
236236
~C() { print_destroyed(this); }
237237
};
238238
py::class_<C, custom_unique_ptr<C>>(m, "TypeWithMoveOnlyHolder")
239-
.def_static("make", []() { return custom_unique_ptr<C>(new C); });
239+
.def_static("make", []() { return custom_unique_ptr<C>(new C); })
240+
.def_static("make_as_object", []() { return py::cast(custom_unique_ptr<C>(new C)); });
240241

241242
// test_smart_ptr_from_default
242243
struct HeldByDefaultHolder { };

tests/test_smart_ptr.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,10 @@ def test_shared_ptr_from_this_and_references():
197197

198198
def test_move_only_holder():
199199
a = m.TypeWithMoveOnlyHolder.make()
200+
b = m.TypeWithMoveOnlyHolder.make_as_object()
200201
stats = ConstructorStats.get(m.TypeWithMoveOnlyHolder)
202+
assert stats.alive() == 2
203+
del b
201204
assert stats.alive() == 1
202205
del a
203206
assert stats.alive() == 0

0 commit comments

Comments
 (0)