Fix crash in def_readwrite for non-smart-holder properties of smart-holder classes (v2) (#6008)

* Add tests that cause crash in def_readwrite

- Occurs with non-smart-holder property of smart-holder class

* Fix crash in def_readwrite for non-smart-holder properties of smart-holder classes

* Use default policy

* Address PR comments

* Add test for cast error path

* style: pre-commit fixes

* Revert "Use default policy"

This reverts commit b299f32104.

* Disable test_shared_ptr_return_for_unique_ptr_holder when PYBIND11_TEST_SMART_HOLDER=ON

* Add counterexample

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
This commit is contained in:
Dustin Spicuzza
2026-03-24 10:58:42 -04:00
committed by GitHub
parent 2d1723c0d6
commit ce9f83c700
4 changed files with 94 additions and 1 deletions

View File

@@ -96,6 +96,12 @@ PYBIND11_MODULE(pybind11_tests, m, py::mod_gil_not_used()) {
#else
false;
#endif
m.attr("PYBIND11_TEST_SMART_HOLDER") =
#if defined(PYBIND11_RUN_TESTING_WITH_SMART_HOLDER_AS_DEFAULT_BUT_NEVER_USE_IN_PRODUCTION_PLEASE)
true;
#else
false;
#endif
bind_ConstructorStats(m);