Skip to content

fix: AppleClang 12 warnings #2510

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

Merged
merged 2 commits into from
Sep 19, 2020
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/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2092,7 +2092,7 @@ class unpacking_collector {
}

void process(list &args_list, detail::args_proxy ap) {
for (const auto &a : ap)
for (auto a : ap)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case anyone else wonders "why don't we fix the iterator class", here's why:

  • "Iterator" is this thing
  • operator* returns a py::handle which is generally better to copy than to take by reference.
  • The iterator stores and mutates value, so returning a reference here would be wrong as soon as you advance the iterator.

So this is complete fine.

Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI Sep 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meep! I guess I haven't looked what iterator / const_iterator look like for non-random-access containers in STL 😅

From my understanding, your statement of "why don't we fix the iterator class" means "why don't we change operator* return [const] handle&", which is 100% valid in terms of this PR.

I think there's still question like "what do other libs do for similar patterns and should we adopt that pattern if it enables const T&?", especially for iterators implemented for something like std::list, etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action here, to be clear, just wanted to clarify on the comment)

args_list.append(a);
}

Expand Down Expand Up @@ -2124,7 +2124,7 @@ class unpacking_collector {
void process(list &/*args_list*/, detail::kwargs_proxy kp) {
if (!kp)
return;
for (const auto &k : reinterpret_borrow<dict>(kp)) {
for (auto k : reinterpret_borrow<dict>(kp)) {
if (m_kwargs.contains(k.first)) {
#if defined(NDEBUG)
multiple_values_error();
Expand Down
10 changes: 5 additions & 5 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ struct enum_base {
handle type = type::handle_of(arg);
object type_name = type.attr("__name__");
dict entries = type.attr("__entries");
for (const auto &kv : entries) {
for (auto kv : entries) {
object other = kv.second[int_(0)];
if (other.equal(arg))
return pybind11::str("{}.{}").format(type_name, kv.first);
Expand All @@ -1506,7 +1506,7 @@ struct enum_base {
m_base.attr("name") = property(cpp_function(
[](handle arg) -> str {
dict entries = type::handle_of(arg).attr("__entries");
for (const auto &kv : entries) {
for (auto kv : entries) {
if (handle(kv.second[int_(0)]).equal(arg))
return pybind11::str(kv.first);
}
Expand All @@ -1521,7 +1521,7 @@ struct enum_base {
if (((PyTypeObject *) arg.ptr())->tp_doc)
docstring += std::string(((PyTypeObject *) arg.ptr())->tp_doc) + "\n\n";
docstring += "Members:";
for (const auto &kv : entries) {
for (auto kv : entries) {
auto key = std::string(pybind11::str(kv.first));
auto comment = kv.second[int_(1)];
docstring += "\n\n " + key;
Expand All @@ -1535,7 +1535,7 @@ struct enum_base {
m_base.attr("__members__") = static_property(cpp_function(
[](handle arg) -> dict {
dict entries = arg.attr("__entries"), m;
for (const auto &kv : entries)
for (auto kv : entries)
m[kv.first] = kv.second[int_(0)];
return m;
}, name("__members__")), none(), none(), ""
Expand Down Expand Up @@ -1623,7 +1623,7 @@ struct enum_base {

PYBIND11_NOINLINE void export_values() {
dict entries = m_base.attr("__entries");
for (const auto &kv : entries)
for (auto kv : entries)
m_parent.attr(kv.first) = kv.second[int_(0)];
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test_operator_overloading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::string abs(const Vector2&) {
// Taken from: https://github.com/RobotLocomotion/drake/commit/aaf84b46
// TODO(eric): This could be resolved using a function / functor (e.g. `py::self()`).
#if defined(__APPLE__) && defined(__clang__)
#if (__clang_major__ >= 10) && (__clang_minor__ >= 0) && (__clang_patchlevel__ >= 1)
#if (__clang_major__ >= 10)
#pragma GCC diagnostic ignored "-Wself-assign-overloaded"
#endif
#elif defined(__clang__)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pytypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ TEST_SUBMODULE(pytypes, m) {
d["basic_attr"] = o.attr("basic_attr");

auto l = py::list();
for (const auto &item : o.attr("begin_end")) {
for (auto item : o.attr("begin_end")) {
l.append(item);
}
d["begin_end"] = l;
Expand Down