Skip to content

Commit 06e74d9

Browse files
committed
Reproducer for issue encountered in smart_holder update.
1 parent 7c6f2f8 commit 06e74d9

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/test_class.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ struct NoBraceInitialization {
3636
std::vector<int> vec;
3737
};
3838

39+
namespace test_class {
40+
namespace pr4220 { // PR #4220
41+
42+
template <int> // Using int as a trick to easily generate a series of types.
43+
struct atyp { // Short for "any type".
44+
std::string mtxt;
45+
};
46+
47+
template <typename T>
48+
std::string get_mtxt(const T &obj) {
49+
return obj.mtxt;
50+
}
51+
52+
using atyp_valu = atyp<0x0>;
53+
54+
atyp_valu rtrn_valu() {
55+
atyp_valu obj{"Value"};
56+
return obj;
57+
}
58+
59+
void bind_all(py::module_ m) {
60+
py::class_<atyp_valu>(m, "atyp_valu")
61+
.def(py::init(&rtrn_valu))
62+
.def("get_mtxt", get_mtxt<atyp_valu>);
63+
}
64+
65+
} // namespace pr4220
66+
} // namespace test_class
67+
3968
TEST_SUBMODULE(class_, m) {
4069
// test_instance
4170
struct NoConstructor {
@@ -517,6 +546,8 @@ TEST_SUBMODULE(class_, m) {
517546
py::class_<OtherDuplicateNested>(gt, "OtherDuplicateNested");
518547
py::class_<OtherDuplicateNested>(gt, "YetAnotherDuplicateNested");
519548
});
549+
550+
test_class::pr4220::bind_all(m);
520551
}
521552

522553
template <int N>

tests/test_class.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,7 @@ class ClassScope:
469469
m.register_duplicate_nested_class_type(ClassScope)
470470
expected = 'generic_type: type "YetAnotherDuplicateNested" is already registered!'
471471
assert str(exc_info.value) == expected
472+
473+
474+
def test_pr4220_bind_all():
475+
assert m.atyp_valu().get_mtxt() == "Value"

0 commit comments

Comments
 (0)