new clang-tidy checker for assignments within the condition clause of an 'if' statement.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst | ||
---|---|---|
9 ↗ | (On Diff #434472) | Why not improve -Wparentheses to catch these cases too? |
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst | ||
---|---|---|
9 ↗ | (On Diff #434472) | IMHO, -Wparentheses isn't broken. Its "disable warning by an extra set of parentheses" behavior has been around for a long time and is common across gcc and clang... it just isn't what is called for when trying to ensure that accidental assignments aren't occurring in even slightly complicated condition statements, or when trying to comply with BARR-group coding standard. |
clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.cpp | ||
---|---|---|
39 ↗ | (On Diff #434472) | Please follow Clang's message style. The message should start with a lowercase letter and should not end with a period. Suggested fixes (since there are multiple) should be in notes. warning: an assignment within an 'if' condition is bug-prone Also consider adding a fixit to the second note. |
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst | ||
3 ↗ | (On Diff #434472) | WDYT about bugprone-assignment-in-if-condition? |
6–9 ↗ | (On Diff #434472) | |
9 ↗ | (On Diff #434472) | Oh, I see -- it wasn't clear to me that the silencing through the extra set of parens was specifically not desirable for you. I suggested some edits to the documentation to directly highlight the difference. I also suggest changing the example below to explicitly mention what assignments are flagged by -Wparentheses and which are flagged by this check. |
10 ↗ | (On Diff #434472) | |
17 ↗ | (On Diff #434472) | The "static volatile" part is not relevant to the example, and it might distract the reader, suggesting that something is special about such variables. |
clang-tools-extra/test/clang-tidy/checkers/misc-assignment-in-if-clause.cpp | ||
68 ↗ | (On Diff #434472) | Please clang-format the test. |
clang-tools-extra/clang-tidy/misc/AssignmentInIfClauseCheck.cpp | ||
---|---|---|
39 ↗ | (On Diff #434472) | Will adjust the messages. I'm specifically reluctant to add a fixit to this, as I'm not sure how I can tell an intended assignment (for which the fix would be moving the assignment out of the if clause) apart from an accidental assignment (for which the fix is changing '=' to '=='). Thoughts? |
clang-tools-extra/docs/clang-tidy/checks/misc-assignment-in-if-clause.rst | ||
3 ↗ | (On Diff #434472) | I'm in favor of that categorization - it reflects how I feel about having assignments within an 'if' condition. I'll change it accordingly |
renamed from misc-assignment-in-if-clause to bugprone-assignment-in-if-condition per review input
Adjusted documentation per review input.
Hi @alexfh , @aaron.ballman, Could one of you have a look at this? I'd like to get it moving toward resolution and don't know who else ought to do a review...
clang-tools-extra/test/clang-tidy/checkers/bugprone-assignment-in-if-condition.cpp | ||
---|---|---|
85 |
Addressing comments from @gribozavr2 identifying comments needing update/removal/improvement.
Hi @gribozavr2, I don't have commit access... I'll address the merge issue ASAP though.
Thanks! I'll commit this for you once you upload a refreshed patch (that applies to the main branch cleanly).