diff --git a/tests/test_builtin_casters.cpp b/tests/test_builtin_casters.cpp index 7b67515e5..6529f47d0 100644 --- a/tests/test_builtin_casters.cpp +++ b/tests/test_builtin_casters.cpp @@ -267,7 +267,8 @@ TEST_SUBMODULE(builtin_casters, m) { m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; }); static std::pair int_string_pair{2, "items"}; - m.def("int_string_pair", []() { return &int_string_pair; }); + m.def( + "int_string_pair", []() { return &int_string_pair; }, py::return_value_policy::reference); // test_builtins_cast_return_none m.def("return_none_string", []() -> std::string * { return nullptr; }); diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index b56a91953..38d32fda9 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -177,7 +177,8 @@ TEST_SUBMODULE(stl, m) { [](const std::vector &v) { return v.at(0) == true && v.at(1) == false; }); // Unnumbered regression (caused by #936): pointers to stl containers aren't castable static std::vector lvv{2}; - m.def("cast_ptr_vector", []() { return &lvv; }); + m.def( + "cast_ptr_vector", []() { return &lvv; }, py::return_value_policy::reference); // test_deque m.def("cast_deque", []() { return std::deque{1}; });