Skip to content

Commit 75adb12

Browse files
authored
[clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)
Properly ignore parentheses in bitwise operators. Closes #81515
1 parent b366643 commit 75adb12

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void NonZeroEnumToBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
6464
EnumIgnoreList)))
6565
.bind("enum"))))),
6666
unless(declRefExpr(to(enumConstantDecl()))),
67-
unless(ignoringImplicit(ExcludedOperators)))),
67+
unless(ignoringParenImpCasts(ExcludedOperators)))),
6868
unless(hasAncestor(staticAssertDecl())))
6969
.bind("cast"),
7070
this);

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ New check aliases
112112
Changes in existing checks
113113
^^^^^^^^^^^^^^^^^^^^^^^^^^
114114

115+
- Improved :doc:`bugprone-non-zero-enum-to-bool-conversion
116+
<clang-tidy/checks/bugprone/non-zero-enum-to-bool-conversion>` check by
117+
eliminating false positives resulting from direct usage of bitwise operators
118+
within parentheses.
119+
115120
- Improved :doc:`bugprone-suspicious-include
116121
<clang-tidy/checks/bugprone/suspicious-include>` check by replacing the local
117122
options `HeaderFileExtensions` and `ImplementationFileExtensions` by the

clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { retur
122122

123123
void testCustomOperator(CustomOperatorEnum e) {
124124
if (e & E1) {}
125+
if ((e & E1)) {}
126+
if (!(e & E1)) {}
125127
}
126128

127129
}

0 commit comments

Comments
 (0)