diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 14992be4..b2329643 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -580,6 +580,7 @@ class type_caster_generic { wrapper->owned = false; break; + case return_value_policy::_clif_automatic: case return_value_policy::copy: if (copy_constructor) { valueptr = copy_constructor(src); diff --git a/tests/test_copy_move.cpp b/tests/test_copy_move.cpp index f5473355..087b4852 100644 --- a/tests/test_copy_move.cpp +++ b/tests/test_copy_move.cpp @@ -294,6 +294,15 @@ TEST_SUBMODULE(copy_move_policies, m) { // Make sure that cast from pytype rvalue to other pytype works m.def("get_pytype_rvalue_castissue", [](double i) { return py::float_(i).cast(); }); + + // Mimic situation generated by PyCLIF-pybind11. + // Requires `case return_value_policy::_clif_automatic` in `type_caster_base`. + struct PyCastUsingClifAutomaticTestType {}; + py::class_(m, "PyCastUsingClifAutomaticTestType"); + m.def("py_cast_using_clif_automatic", []() { + PyCastUsingClifAutomaticTestType cpp_obj; + return py::cast(cpp_obj, py::return_value_policy::_clif_automatic); + }); } /* diff --git a/tests/test_copy_move.py b/tests/test_copy_move.py index 9fef0893..16f7dd5e 100644 --- a/tests/test_copy_move.py +++ b/tests/test_copy_move.py @@ -130,3 +130,8 @@ def test_pytype_rvalue_cast(): value = m.get_pytype_rvalue_castissue(1.0) assert value == 1 + + +def test_py_cast_using_clif_automatic(): + obj = m.py_cast_using_clif_automatic() + assert obj.__class__.__name__ == "PyCastUsingClifAutomaticTestType"