Skip to content

Commit

Permalink
Failing test on mismatching function arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaschke committed Oct 20, 2020
1 parent 793b217 commit 81e1d6c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/test_smart_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);
// holder size to trigger the non-simple-layout internal instance layout for single inheritance with
// large holder type:
template <typename T> class huge_unique_ptr {
std::unique_ptr<T> ptr;
uint64_t padding[10];
std::unique_ptr<T> ptr;
public:
huge_unique_ptr(T *p) : ptr(p) {};
T *get() const { return ptr.get(); }
Expand Down Expand Up @@ -382,4 +382,6 @@ TEST_SUBMODULE(smart_ptr, m) {
// Fails: `return_shared' already returned this via shared_ptr holder
py::class_<HeldByUnique>(m, "HeldByUnique");
});
// segfaults, because std::shared_ptr<MyObject5> is interpreted as huge_unique_ptr<MyObject5>
m.def("consume_mismatching_holder", [](std::shared_ptr<MyObject5> o) { return o->value; });
}
2 changes: 2 additions & 0 deletions tests/test_smart_ptr.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,5 @@ def test_holder_mismatch():
with pytest.raises(RuntimeError) as excinfo:
m.register_mismatch_class(m)
assert "Mismatched holders detected" in str(excinfo)

assert m.consume_mismatching_holder(m.MyObject5(42)) == 42

0 comments on commit 81e1d6c

Please sign in to comment.