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

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented Sep 19, 2020

Fixing two sets of warnings in AppleClang 12. First is a warning that you can't really take a reference to a temporary object, so this will actually always be a copy, and should be clearly written as such.

Second is a bug where 11.0.0 or 12.0.0 or X.X.0 AppleClang will produce a warning due not passing an if statement. It's just a pragma so it should be safe even if the version doesn't match? CC @EricCousineau-TRI (I think).

Closes #2509

@henryiii henryiii changed the title fix: AppleClang 12 fix: AppleClang 12 warnings Sep 19, 2020
@@ -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)

Copy link
Collaborator

@EricCousineau-TRI EricCousineau-TRI left a comment

Choose a reason for hiding this comment

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

Thanks for the heads up on the Apple #ifdef change!

@YannickJadoul
Copy link
Collaborator

Thanks for the extra clarification, @bstaletic & @EricCousineau-TRI!

Given that this is a simple fix, I think it can safely go in.

@YannickJadoul YannickJadoul merged commit d0ed035 into pybind:master Sep 19, 2020
henryiii added a commit to henryiii/pybind11 that referenced this pull request Sep 22, 2020
Fixed in pybind#2510 but reintroduced on one line by pybind#2126
YannickJadoul pushed a commit that referenced this pull request Sep 22, 2020
Fixed in #2510 but reintroduced on one line by #2126
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] New warning in AppleClang 12
4 participants