Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Clazy warnings #4988

Merged
merged 2 commits into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/pybind11/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct list_caster {
auto s = reinterpret_borrow<sequence>(src);
value.clear();
reserve_maybe(s, &value);
for (auto it : s) {
for (const auto &it : s) {
value_conv conv;
if (!conv.load(it, convert)) {
return false;
Expand Down Expand Up @@ -247,7 +247,7 @@ struct array_caster {
return false;
}
size_t ctr = 0;
for (auto it : l) {
for (const auto &it : l) {
value_conv conv;
if (!conv.load(it, convert)) {
return false;
Expand Down
27 changes: 15 additions & 12 deletions tests/test_smart_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,57 +103,60 @@ class MyObject3 : public std::enable_shared_from_this<MyObject3> {
int value;
};

template <typename T>
std::unordered_set<T *> &pointer_set() {
// https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
static auto singleton = new std::unordered_set<T *>();
return *singleton;
}

// test_unique_nodelete
// Object with a private destructor
class MyObject4;
std::unordered_set<MyObject4 *> myobject4_instances;
class MyObject4 {
public:
explicit MyObject4(int value) : value{value} {
print_created(this);
myobject4_instances.insert(this);
pointer_set<MyObject4>().insert(this);
}
int value;

static void cleanupAllInstances() {
auto tmp = std::move(myobject4_instances);
myobject4_instances.clear();
auto tmp = std::move(pointer_set<MyObject4>());
pointer_set<MyObject4>().clear();
for (auto *o : tmp) {
delete o;
}
}

private:
~MyObject4() {
myobject4_instances.erase(this);
pointer_set<MyObject4>().erase(this);
print_destroyed(this);
}
};

// test_unique_deleter
// Object with std::unique_ptr<T, D> where D is not matching the base class
// Object with a protected destructor
class MyObject4a;
std::unordered_set<MyObject4a *> myobject4a_instances;
class MyObject4a {
public:
explicit MyObject4a(int i) : value{i} {
print_created(this);
myobject4a_instances.insert(this);
pointer_set<MyObject4a>().insert(this);
};
int value;

static void cleanupAllInstances() {
auto tmp = std::move(myobject4a_instances);
myobject4a_instances.clear();
auto tmp = std::move(pointer_set<MyObject4a>());
pointer_set<MyObject4a>().clear();
for (auto *o : tmp) {
delete o;
}
}

protected:
virtual ~MyObject4a() {
myobject4a_instances.erase(this);
pointer_set<MyObject4a>().erase(this);
print_destroyed(this);
}
};
Expand Down