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:
@@ -177,7 +177,8 @@ TEST_SUBMODULE(stl, m) {
|
||||
[](const std::vector<bool> &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<RValueCaster> 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<int>{1}; });
|
||||
|
||||
Reference in New Issue
Block a user