[clang-tools-extra] df42f99 - [clang-tidy] Simplify suspicious enum usage check
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 27 04:15:19 PST 2021
Author: Stephen Kelly
Date: 2021-02-27T12:11:45Z
New Revision: df42f9950d5e4aaea2038581188ed9d786d09213
URL: https://github.com/llvm/llvm-project/commit/df42f9950d5e4aaea2038581188ed9d786d09213
DIFF: https://github.com/llvm/llvm-project/commit/df42f9950d5e4aaea2038581188ed9d786d09213.diff
LOG: [clang-tidy] Simplify suspicious enum usage check
Differential Revision: https://reviews.llvm.org/D97149
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
index 3faa28c0158a..73068610a53b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.cpp
@@ -118,30 +118,28 @@ void SuspiciousEnumUsageCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
void SuspiciousEnumUsageCheck::registerMatchers(MatchFinder *Finder) {
const auto EnumExpr = [](StringRef RefName, StringRef DeclName) {
- return expr(ignoringImpCasts(expr().bind(RefName)),
- ignoringImpCasts(hasType(enumDecl().bind(DeclName))));
+ return expr(hasType(enumDecl().bind(DeclName))).bind(RefName);
};
Finder->addMatcher(
- binaryOperator(hasOperatorName("|"), hasLHS(EnumExpr("", "enumDecl")),
- hasRHS(expr(EnumExpr("", "otherEnumDecl"),
- ignoringImpCasts(hasType(enumDecl(
- unless(equalsBoundNode("enumDecl"))))))))
+ binaryOperator(
+ hasOperatorName("|"), hasLHS(hasType(enumDecl().bind("enumDecl"))),
+ hasRHS(hasType(enumDecl(unless(equalsBoundNode("enumDecl")))
+ .bind("otherEnumDecl"))))
.bind("
diff EnumOp"),
this);
Finder->addMatcher(
binaryOperator(hasAnyOperatorName("+", "|"),
hasLHS(EnumExpr("lhsExpr", "enumDecl")),
- hasRHS(expr(EnumExpr("rhsExpr", ""),
- ignoringImpCasts(hasType(
- enumDecl(equalsBoundNode("enumDecl"))))))),
+ hasRHS(expr(hasType(enumDecl(equalsBoundNode("enumDecl"))))
+ .bind("rhsExpr"))),
this);
Finder->addMatcher(
binaryOperator(
hasAnyOperatorName("+", "|"),
- hasOperands(expr(hasType(isInteger()), unless(EnumExpr("", ""))),
+ hasOperands(expr(hasType(isInteger()), unless(hasType(enumDecl()))),
EnumExpr("enumExpr", "enumDecl"))),
this);
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h
index f05f3e1c54e0..7541810cdb1b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousEnumUsageCheck.h
@@ -25,6 +25,9 @@ class SuspiciousEnumUsageCheck : public ClangTidyCheck {
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
void checkSuspiciousBitmaskUsage(const Expr*, const EnumDecl*);
More information about the cfe-commits
mailing list