Skip to content

Commit

Permalink
[clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to…
Browse files Browse the repository at this point in the history
…-bool-conversion (#81890)

Properly ignore parentheses in bitwise operators.

Closes #81515
  • Loading branch information
PiotrZSL committed Feb 17, 2024
1 parent b366643 commit 75adb12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void NonZeroEnumToBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
EnumIgnoreList)))
.bind("enum"))))),
unless(declRefExpr(to(enumConstantDecl()))),
unless(ignoringImplicit(ExcludedOperators)))),
unless(ignoringParenImpCasts(ExcludedOperators)))),
unless(hasAncestor(staticAssertDecl())))
.bind("cast"),
this);
Expand Down
5 changes: 5 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ New check aliases
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^

- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
eliminating false positives resulting from direct usage of bitwise operators
within parentheses.

- Improved :doc:`bugprone-suspicious-include
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
options `HeaderFileExtensions` and `ImplementationFileExtensions` by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { retur

void testCustomOperator(CustomOperatorEnum e) {
if (e & E1) {}
if ((e & E1)) {}
if (!(e & E1)) {}
}

}

0 comments on commit 75adb12

Please sign in to comment.