Skip to content

Commit 00257be

Browse files
committed
[skip ci] Also exercise smart_holder::from_raw_ptr_take_ownership
1 parent 7d047e8 commit 00257be

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

tests/test_class_sh_mi_thunks.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,22 @@ struct Diamond : Left, Right {
5454
int self_tag = 99;
5555
};
5656

57+
// Factory that returns the *virtual base* type (raw pointer)
58+
VBase *make_diamond_as_vbase_raw_ptr() {
59+
auto ptr = new Diamond;
60+
return ptr; // upcast
61+
}
62+
5763
// Factory that returns the *virtual base* type (shared_ptr)
5864
std::shared_ptr<VBase> make_diamond_as_vbase_shared_ptr() {
5965
auto shptr = std::make_shared<Diamond>();
60-
return shptr; // upcast to VBase shared_ptr (virtual base)
66+
return shptr; // upcast
6167
}
6268

6369
// Factory that returns the *virtual base* type (unique_ptr)
6470
std::unique_ptr<VBase> make_diamond_as_vbase_unique_ptr() {
6571
auto uqptr = std::unique_ptr<Diamond>(new Diamond);
66-
return uqptr; // upcast to VBase unique_ptr (virtual base)
72+
return uqptr; // upcast
6773
}
6874

6975
// For diagnostics / skip decisions in test
@@ -152,6 +158,9 @@ TEST_SUBMODULE(class_sh_mi_thunks, m) {
152158
.def(py::init<>())
153159
.def("ping", &Diamond::ping);
154160

161+
m.def("make_diamond_as_vbase_raw_ptr",
162+
&make_diamond_as_vbase_raw_ptr,
163+
py::return_value_policy::take_ownership);
155164
m.def("make_diamond_as_vbase_shared_ptr", &make_diamond_as_vbase_shared_ptr);
156165
m.def("make_diamond_as_vbase_unique_ptr", &make_diamond_as_vbase_unique_ptr);
157166

tests/test_class_sh_mi_thunks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ def test_virtual_base_at_offset_0():
6262
@pytest.mark.parametrize(
6363
"make_fn",
6464
[
65+
m.make_diamond_as_vbase_raw_ptr, # exercises smart_holder::from_raw_ptr_take_ownership
6566
m.make_diamond_as_vbase_shared_ptr, # exercises smart_holder_from_shared_ptr
6667
m.make_diamond_as_vbase_unique_ptr, # exercises smart_holder_from_unique_ptr
6768
],
6869
)
69-
def test_shared_ptr_return_to_virtual_base_triggers_vi_path(make_fn):
70+
def test_make_diamond_as_vbase(make_fn):
7071
# See PR #5836 for background
7172
vb = make_fn()
7273
assert vb.ping() == 7

0 commit comments

Comments
 (0)