Skip to content

Commit 81e1d6c

Browse files
committed
Failing test on mismatching function arguments
1 parent 793b217 commit 81e1d6c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

tests/test_smart_ptr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
3737
// holder size to trigger the non-simple-layout internal instance layout for single inheritance with
3838
// large holder type:
3939
template <typename T> class huge_unique_ptr {
40-
std::unique_ptr<T> ptr;
4140
uint64_t padding[10];
41+
std::unique_ptr<T> ptr;
4242
public:
4343
huge_unique_ptr(T *p) : ptr(p) {};
4444
T *get() const { return ptr.get(); }
@@ -382,4 +382,6 @@ TEST_SUBMODULE(smart_ptr, m) {
382382
// Fails: `return_shared' already returned this via shared_ptr holder
383383
py::class_<HeldByUnique>(m, "HeldByUnique");
384384
});
385+
// segfaults, because std::shared_ptr<MyObject5> is interpreted as huge_unique_ptr<MyObject5>
386+
m.def("consume_mismatching_holder", [](std::shared_ptr<MyObject5> o) { return o->value; });
385387
}

tests/test_smart_ptr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,5 @@ def test_holder_mismatch():
319319
with pytest.raises(RuntimeError) as excinfo:
320320
m.register_mismatch_class(m)
321321
assert "Mismatched holders detected" in str(excinfo)
322+
323+
assert m.consume_mismatching_holder(m.MyObject5(42)) == 42

0 commit comments

Comments
 (0)