diff options
author | Piotr Zegar <piotr.zegar@nokia.com> | 2024-02-17 08:58:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-17 08:58:22 +0100 |
commit | 75adb1226905693ac57e563f675e282e78ac491e (patch) | |
tree | 5190a520c84d33c36046ece442c9757a35dd885c /clang-tools-extra | |
parent | b366643ca3d780931afed6bff7148a4822e51119 (diff) | |
download | llvm-75adb1226905693ac57e563f675e282e78ac491e.zip llvm-75adb1226905693ac57e563f675e282e78ac491e.tar.gz llvm-75adb1226905693ac57e563f675e282e78ac491e.tar.bz2 |
[clang-tidy] Fix handling of parentheses in bugprone-non-zero-enum-to-bool-conversion (#81890)
Properly ignore parentheses in bitwise operators.
Closes #81515
Diffstat (limited to 'clang-tools-extra')
3 files changed, 8 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp index 918b6e3..e032384 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 6b0c85e..737ea9b 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 794e7b2..3375f69 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)) {} } } |