mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
Don't return pointers to static objects with return_value_policy::take_ownership. (#3946)
* Don't return pointers to static objects with return_value_policy::take_ownership. This fixes -Wfree-nonheap-object warnings produced by GCC. * Use return value policy fix instead Co-authored-by: Aaron Gokaslan <skylion.aaron@gmail.com>
This commit is contained in:
@@ -267,7 +267,8 @@ TEST_SUBMODULE(builtin_casters, m) {
|
||||
m.def("lvalue_nested", []() -> const decltype(lvnested) & { return lvnested; });
|
||||
|
||||
static std::pair<int, std::string> 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; });
|
||||
|
||||
Reference in New Issue
Block a user