Reproducer for issue encountered in smart_holder update.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-10-07 14:41:54 -07:00
parent 7c6f2f80a7
commit 06e74d9d46
2 changed files with 35 additions and 0 deletions

View File

@ -36,6 +36,35 @@ struct NoBraceInitialization {
std::vector<int> vec;
};
namespace test_class {
namespace pr4220 { // PR #4220
template <int> // Using int as a trick to easily generate a series of types.
struct atyp { // Short for "any type".
std::string mtxt;
};
template <typename T>
std::string get_mtxt(const T &obj) {
return obj.mtxt;
}
using atyp_valu = atyp<0x0>;
atyp_valu rtrn_valu() {
atyp_valu obj{"Value"};
return obj;
}
void bind_all(py::module_ m) {
py::class_<atyp_valu>(m, "atyp_valu")
.def(py::init(&rtrn_valu))
.def("get_mtxt", get_mtxt<atyp_valu>);
}
} // namespace pr4220
} // namespace test_class
TEST_SUBMODULE(class_, m) {
// test_instance
struct NoConstructor {
@ -517,6 +546,8 @@ TEST_SUBMODULE(class_, m) {
py::class_<OtherDuplicateNested>(gt, "OtherDuplicateNested");
py::class_<OtherDuplicateNested>(gt, "YetAnotherDuplicateNested");
});
test_class::pr4220::bind_all(m);
}
template <int N>

View File

@ -469,3 +469,7 @@ def test_register_duplicate_class():
m.register_duplicate_nested_class_type(ClassScope)
expected = 'generic_type: type "YetAnotherDuplicateNested" is already registered!'
assert str(exc_info.value) == expected
def test_pr4220_bind_all():
assert m.atyp_valu().get_mtxt() == "Value"