[clang-tools-extra] 75adb12 - [clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 16 23:58:26 PST 2024
Author: Piotr Zegar
Date: 2024-02-17T08:58:22+01:00
New Revision: 75adb1226905693ac57e563f675e282e78ac491e
URL: https://github.com/llvm/llvm-project/commit/75adb1226905693ac57e563f675e282e78ac491e
DIFF: https://github.com/llvm/llvm-project/commit/75adb1226905693ac57e563f675e282e78ac491e.diff
LOG: [clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)
Properly ignore parentheses in bitwise operators.
Closes #81515
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
index 918b6e3824f0b1..e0323848870bd7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
@@ -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);
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 6b0c85ea84e6c6..737ea9ba6d44f7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -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
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
index 794e7b20c8ca53..3375f69b591119 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/non-zero-enum-to-bool-conversion.cpp
@@ -122,6 +122,8 @@ CustomOperatorEnum operator&(CustomOperatorEnum a, CustomOperatorEnum b) { retur
void testCustomOperator(CustomOperatorEnum e) {
if (e & E1) {}
+ if ((e & E1)) {}
+ if (!(e & E1)) {}
}
}
More information about the cfe-commits
mailing list