mirror of
https://github.com/pybind/pybind11.git
synced 2025-03-12 07:49:28 +00:00
Reproducer for issue encountered in smart_holder update.
This commit is contained in:
parent
7c6f2f80a7
commit
06e74d9d46
@ -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>
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user