[clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)

Properly ignore parentheses in bitwise operators.

Closes #81515
This commit is contained in:
Piotr Zegar 2024-02-17 08:58:22 +01:00 committed by GitHub
parent b366643ca3
commit 75adb12269
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 1 deletions

View File

@ -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);

View File

@ -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

View File

@ -122,6 +122,8 @@ CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { retur
void testCustomOperator(CustomOperatorEnum e) {
if (e & E1) {}
if ((e & E1)) {}
if (!(e & E1)) {}
}
}