Add a fix-it for the common case of setters/constructors using parameters with the same name as fields
struct A{ int X; A(int X) { /*this->*/X = X; } void setX(int X) { /*this->*/X = X; };
Differential D129202
[clang] Add a fixit for warn-self-assign if LHS is a field with the same name as parameter on RHS njames93 on Jul 6 2022, 7:08 AM. Authored by
Details Add a fix-it for the common case of setters/constructors using parameters with the same name as fields struct A{ int X; A(int X) { /*this->*/X = X; } void setX(int X) { /*this->*/X = X; };
Diff Detail
Event TimelineComment Actions Thank you for working on this, I think it's a nice new diagnostic. You should add a release note to describe it. One question I have is about how chatty this is over real world code, especially older code bases. There used to be two prevailing ways to silence the "unused variable" warnings you would get when a variable is used in an assert: (void)whatever; and whatever = whatever;; I'm worried the latter case is still prevalent enough that having this warning on by default would be a problem, but I'm also optimistic my worry is unfounded.
Comment Actions It's not adding a new warning, so chattiness of this patch shouldn't really be much of an issue.
Comment Actions It's not triggering a diagnostic in a situation we didn't used to diagnose, but it is doubling the number of diagnostics emitted in some circumstances. So it's not a new warning, but chattiness is still a valid concern. We don't want to swamp the user with diagnostic messages.
Comment Actions Attach fix directly to the warning. Comment Actions LGTM with some minor stuff you can fix when landing. Thank you for this!
|
We don't normally have trailing punctuation... except for question marks which we will happily use when asking the user a question.