diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index ead4006ef..547f377a7 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1636,7 +1636,7 @@ struct property_cpp_function< D, detail::enable_if_t< detail::all_of, detail::type_caster>, - std::is_base_of, detail::type_caster>, + std::is_base_of, detail::make_caster>, std::is_pointer>::value>> { using drp = typename std::remove_pointer::type; @@ -1686,6 +1686,7 @@ struct property_cpp_function< detail::all_of, detail::type_caster>, std::is_base_of, detail::type_caster>, detail::none_of, + std::is_array, detail::is_instantiation, detail::is_instantiation>>::value>> { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b79e755e4..28fb275c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -127,6 +127,7 @@ set(PYBIND11_TEST_FILES test_class_sh_mi_thunks test_class_sh_module_local.py test_class_sh_property + test_class_sh_property_bakein test_class_sh_property_non_owning test_class_sh_shared_ptr_copy_move test_class_sh_trampoline_basic diff --git a/tests/test_class_sh_property_bakein.cpp b/tests/test_class_sh_property_bakein.cpp new file mode 100644 index 000000000..0fae55101 --- /dev/null +++ b/tests/test_class_sh_property_bakein.cpp @@ -0,0 +1,26 @@ +#include "pybind11_tests.h" + +namespace test_class_sh_property_bakein { + +struct WithCharArrayMember { + WithCharArrayMember() { std::strcpy(char6_member, "Char6"); } + char char6_member[6]; +}; + +struct WithConstCharPtrMember { + const char *const_char_ptr_member = "ConstChar*"; +}; + +} // namespace test_class_sh_property_bakein + +TEST_SUBMODULE(class_sh_property_bakein, m) { + using namespace test_class_sh_property_bakein; + + py::class_(m, "WithCharArrayMember") + .def(py::init<>()) + .def_readonly("char6_member", &WithCharArrayMember::char6_member); + + py::class_(m, "WithConstCharPtrMember") + .def(py::init<>()) + .def_readonly("const_char_ptr_member", &WithConstCharPtrMember::const_char_ptr_member); +} diff --git a/tests/test_class_sh_property_bakein.py b/tests/test_class_sh_property_bakein.py new file mode 100644 index 000000000..746231859 --- /dev/null +++ b/tests/test_class_sh_property_bakein.py @@ -0,0 +1,13 @@ +from __future__ import annotations + +from pybind11_tests import class_sh_property_bakein as m + + +def test_readonly_char6_member(): + obj = m.WithCharArrayMember() + assert obj.char6_member == "Char6" + + +def test_readonly_const_char_ptr_member(): + obj = m.WithConstCharPtrMember() + assert obj.const_char_ptr_member == "ConstChar*"