-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix a clang warning [-Wshadow-field-in-constructor-modified] #2780
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
warning: modifying constructor parameter 'flag' that shadows a field of 'set_flag' [-Wshadow-field-in-constructor-modified]
include/pybind11/pybind11.h
Outdated
@@ -1910,7 +1910,7 @@ template <return_value_policy Policy = return_value_policy::reference_internal, | |||
template <typename InputType, typename OutputType> void implicitly_convertible() { | |||
struct set_flag { | |||
bool &flag; | |||
set_flag(bool &flag) : flag(flag) { flag = true; } | |||
set_flag(bool &my_flag) : flag(my_flag) { my_flag = true; } |
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.
my_flag
sounds very tutorial-for-programming-like, though. Could you change this to flag_
or f
or so (or suggest something else)?
Also (mostly to other reviewers): should we turn on more warning flags in CI? What's our goal when it comes to such warnings?
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.
I figured you would have a preferred naming for something like this, I just couldn't find it. I use m for member
style (mFlag
) so I never have to deal with this in my own code.
I'll use flag_
.
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! I can't really find it either. We do use m_flag
for private class members, but this is a struct, so flag
is part of the interface (well, it's a local struct in a function, so it's not that important, but you don't want to write some_struct.m_flag
, I think :-) )
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.
A quick look seems that f
and flag_
would be the two options. I found instances of both conventions. I think this is fine, though, so thanks!
Can't hurt to silence this, I suppose. |
I'm surprised this is the only one you find, though? I can spot a bunch of other struct members and constructor arguments in |
Hmmm... you're right - that is surprising. I'm using a tiny subset of the API, but I see that |
This is a pretty specific warning, due to the fact you modify a value passed in. This is really weird out of context, it's setting the value and then changing the input to True? bool val = False;
set_flag new_flag(val);
// val is now True, new_flag contains False. Big fan of the change making this clearer! |
Oh, I think I see what's going on. Isn't this guarding against re-entrance/infinite recursion of the implicit conversion, during the |
Right, I see, indeed. This could be an issue because it's not clear which |
Description
Fix warning from Apple clang version 11.0.0 (clang-1100.0.33.17)
Suggested changelog entry: