-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Conversation
@@ -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) |
There was a problem hiding this comment.
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 apy::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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this 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!
Thanks for the extra clarification, @bstaletic & @EricCousineau-TRI! Given that this is a simple fix, I think it can safely go in. |
Fixed in pybind#2510 but reintroduced on one line by pybind#2126
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