[clang-tools-extra] ea2225a - [clang-tidy] Simplify readability checks to not need ignoring* matchers
Stephen Kelly via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 28 03:26:17 PDT 2021
Author: Stephen Kelly
Date: 2021-03-28T11:25:41+01:00
New Revision: ea2225a10be986d226e041d20d36dff17e78daed
URL: https://github.com/llvm/llvm-project/commit/ea2225a10be986d226e041d20d36dff17e78daed
DIFF: https://github.com/llvm/llvm-project/commit/ea2225a10be986d226e041d20d36dff17e78daed.diff
LOG: [clang-tidy] Simplify readability checks to not need ignoring* matchers
Differential Revision: https://reviews.llvm.org/D98296
Added:
Modified:
clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.h
clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
index 2c78258078eae..fe25f7a7ccbcc 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.cpp
@@ -105,10 +105,7 @@ void BracesAroundStatementsCheck::storeOptions(
}
void BracesAroundStatementsCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- ifStmt(unless(allOf(isConstexpr(), isInTemplateInstantiation())))
- .bind("if"),
- this);
+ Finder->addMatcher(ifStmt().bind("if"), this);
Finder->addMatcher(whileStmt().bind("while"), this);
Finder->addMatcher(doStmt().bind("do"), this);
Finder->addMatcher(forStmt().bind("for"), this);
diff --git a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.h b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.h
index 7c019c6cb5521..1270cfe10d193 100644
--- a/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/BracesAroundStatementsCheck.h
@@ -55,6 +55,9 @@ class BracesAroundStatementsCheck : public ClangTidyCheck {
template <typename IfOrWhileStmt>
SourceLocation findRParenLoc(const IfOrWhileStmt *S, const SourceManager &SM,
const ASTContext *Context);
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
std::set<const Stmt *> ForceBracesStmts;
diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
index 89bb02e78cc63..0558b41016379 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.cpp
@@ -171,8 +171,7 @@ void ElseAfterReturnCheck::registerPPCallbacks(const SourceManager &SM,
void ElseAfterReturnCheck::registerMatchers(MatchFinder *Finder) {
const auto InterruptsControlFlow = stmt(anyOf(
returnStmt().bind(InterruptingStr), continueStmt().bind(InterruptingStr),
- breakStmt().bind(InterruptingStr),
- expr(ignoringImplicit(cxxThrowExpr().bind(InterruptingStr)))));
+ breakStmt().bind(InterruptingStr), cxxThrowExpr().bind(InterruptingStr)));
Finder->addMatcher(
compoundStmt(
forEach(ifStmt(unless(isConstexpr()),
diff --git a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h
index 440cf4b637b73..d3fbc0ac0abe0 100644
--- a/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/ElseAfterReturnCheck.h
@@ -28,6 +28,9 @@ class ElseAfterReturnCheck : public ClangTidyCheck {
Preprocessor *ModuleExpanderPP) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
using ConditionalBranchMap =
llvm::DenseMap<FileID, SmallVector<SourceRange, 1>>;
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
index c28424b11f279..b3945b5a932f5 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.cpp
@@ -294,8 +294,7 @@ void InconsistentDeclarationParameterNameCheck::storeOptions(
void InconsistentDeclarationParameterNameCheck::registerMatchers(
MatchFinder *Finder) {
- Finder->addMatcher(functionDecl(unless(isImplicit()), hasOtherDeclarations())
- .bind("functionDecl"),
+ Finder->addMatcher(functionDecl(hasOtherDeclarations()).bind("functionDecl"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
index aac2f5060aa9c..ca9640fc5a604 100644
--- a/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/InconsistentDeclarationParameterNameCheck.h
@@ -33,6 +33,9 @@ class InconsistentDeclarationParameterNameCheck : public ClangTidyCheck {
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
void markRedeclarationsAsVisited(const FunctionDecl *FunctionDeclaration);
diff --git a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
index 77f93f1999a9d..7b5a22f449c4b 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.cpp
@@ -106,11 +106,7 @@ void MisleadingIndentationCheck::missingBracesCheck(const SourceManager &SM,
}
void MisleadingIndentationCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(
- ifStmt(allOf(hasElse(stmt()),
- unless(allOf(isConstexpr(), isInTemplateInstantiation()))))
- .bind("if"),
- this);
+ Finder->addMatcher(ifStmt(hasElse(stmt())).bind("if"), this);
Finder->addMatcher(
compoundStmt(has(stmt(anyOf(ifStmt(), forStmt(), whileStmt()))))
.bind("compound"),
diff --git a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
index ed5ba5bad1209..a9067032fa945 100644
--- a/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/MisleadingIndentationCheck.h
@@ -27,6 +27,9 @@ class MisleadingIndentationCheck : public ClangTidyCheck {
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
void danglingElseCheck(const SourceManager &SM, ASTContext *Context,
diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
index 5e018ce6172c6..4f81dc49ded7c 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp
@@ -18,7 +18,7 @@ namespace tidy {
namespace readability {
void NamedParameterCheck::registerMatchers(ast_matchers::MatchFinder *Finder) {
- Finder->addMatcher(functionDecl(unless(isInstantiated())).bind("decl"), this);
+ Finder->addMatcher(functionDecl().bind("decl"), this);
}
void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
@@ -26,10 +26,6 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Function = Result.Nodes.getNodeAs<FunctionDecl>("decl");
SmallVector<std::pair<const FunctionDecl *, unsigned>, 4> UnnamedParams;
- // Ignore implicitly generated members.
- if (Function->isImplicit())
- return;
-
// Ignore declarations without a definition if we're not dealing with an
// overriden method.
const FunctionDecl *Definition = nullptr;
diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
index 33a51b4c8dc91..f946e00a00444 100644
--- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.h
@@ -32,6 +32,9 @@ class NamedParameterCheck : public ClangTidyCheck {
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace readability
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
index 1044df0032d80..c9ebf7b6f8ce7 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.cpp
@@ -18,7 +18,7 @@ namespace readability {
void NonConstParameterCheck::registerMatchers(MatchFinder *Finder) {
// Add parameters to Parameters.
- Finder->addMatcher(parmVarDecl(unless(isInstantiated())).bind("Parm"), this);
+ Finder->addMatcher(parmVarDecl().bind("Parm"), this);
// C++ constructor.
Finder->addMatcher(cxxConstructorDecl().bind("Ctor"), this);
@@ -28,13 +28,11 @@ void NonConstParameterCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(declRefExpr().bind("Ref"), this);
// Analyse parameter usage in function.
- Finder->addMatcher(
- traverse(TK_AsIs,
- stmt(anyOf(unaryOperator(hasAnyOperatorName("++", "--")),
- binaryOperator(), callExpr(), returnStmt(),
- cxxConstructExpr()))
- .bind("Mark")),
- this);
+ Finder->addMatcher(stmt(anyOf(unaryOperator(hasAnyOperatorName("++", "--")),
+ binaryOperator(), callExpr(), returnStmt(),
+ cxxConstructExpr()))
+ .bind("Mark"),
+ this);
Finder->addMatcher(varDecl(hasInitializer(anything())).bind("Mark"), this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
index 39959e6190960..a6179d6aa1e89 100644
--- a/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/NonConstParameterCheck.h
@@ -26,6 +26,9 @@ class NonConstParameterCheck : public ClangTidyCheck {
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void onEndOfTranslationUnit() override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
/// Parameter info.
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
index 9e336cb4cf15d..6af77635aa2b1 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.cpp
@@ -32,10 +32,10 @@ bool isLocationInMacroExpansion(const SourceManager &SM, SourceLocation Loc) {
void RedundantControlFlowCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
- functionDecl(
- isDefinition(), returns(voidType()),
- has(compoundStmt(hasAnySubstatement(returnStmt(unless(has(expr())))))
- .bind("return"))),
+ functionDecl(isDefinition(), returns(voidType()),
+ hasBody(compoundStmt(hasAnySubstatement(
+ returnStmt(unless(has(expr())))))
+ .bind("return"))),
this);
Finder->addMatcher(
mapAnyOf(forStmt, cxxForRangeStmt, whileStmt, doStmt)
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
index d4513e6f49a77..6d91c208587fe 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantControlFlowCheck.h
@@ -29,6 +29,10 @@ class RedundantControlFlowCheck : public ClangTidyCheck {
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
+
private:
void
checkRedundantReturn(const ast_matchers::MatchFinder::MatchResult &Result,
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
index 2d14b49e0eea9..36294cd0e9b82 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
@@ -32,7 +32,7 @@ void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) {
llvm::SmallVector<StringRef, 8>(Types.begin(), Types.end()))))));
Finder->addMatcher(
- arraySubscriptExpr(hasBase(ignoringParenImpCasts(
+ arraySubscriptExpr(hasBase(
cxxMemberCallExpr(
has(memberExpr().bind("member")),
on(hasType(qualType(
@@ -40,7 +40,7 @@ void SimplifySubscriptExprCheck::registerMatchers(MatchFinder *Finder) {
hasDescendant(substTemplateTypeParmType()))),
anyOf(TypesMatcher, pointerType(pointee(TypesMatcher)))))),
callee(namedDecl(hasName("data"))))
- .bind("call")))),
+ .bind("call"))),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h
index 4f43cdb726df5..6caaf49de2a3d 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.h
@@ -28,6 +28,9 @@ class SimplifySubscriptExprCheck : 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:
const std::vector<std::string> Types;
diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
index e7d70f06bdb40..df4a39e11ce43 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -39,8 +39,7 @@ void StaticAccessedThroughInstanceCheck::storeOptions(
void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStaticStorageClass()),
- varDecl(hasStaticStorageDuration()))),
- unless(isInTemplateInstantiation()))
+ varDecl(hasStaticStorageDuration()))))
.bind("memberExpression"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
index d12e8211651f3..f80f3605a01fe 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
@@ -30,6 +30,9 @@ class StaticAccessedThroughInstanceCheck : public ClangTidyCheck {
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
private:
const unsigned NameSpecifierNestingThreshold;
diff --git a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
index 45194a8e3d97e..23f8dbbacb685 100644
--- a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.cpp
@@ -39,17 +39,14 @@ void UniqueptrDeleteReleaseCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxDeleteExpr(
unless(isInTemplateInstantiation()),
- has(expr(ignoringParenImpCasts(
- cxxMemberCallExpr(
- callee(
- memberExpr(hasObjectExpression(allOf(
- unless(isTypeDependent()),
- anyOf(hasType(UniquePtrWithDefaultDelete),
- hasType(pointsTo(
- UniquePtrWithDefaultDelete))))),
- member(cxxMethodDecl(hasName("release"))))
- .bind("release_expr")))
- .bind("release_call")))))
+ has(cxxMemberCallExpr(
+ callee(memberExpr(hasObjectExpression(anyOf(
+ hasType(UniquePtrWithDefaultDelete),
+ hasType(pointsTo(
+ UniquePtrWithDefaultDelete)))),
+ member(cxxMethodDecl(hasName("release"))))
+ .bind("release_expr")))
+ .bind("release_call")))
.bind("delete"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
index 88bb82539ac50..a840ac722d19c 100644
--- a/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/UniqueptrDeleteReleaseCheck.h
@@ -26,6 +26,9 @@ class UniqueptrDeleteReleaseCheck : 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:
const bool PreferResetCall;
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
index c4fbeeb4777aa..827711e92e877 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.cpp
@@ -196,12 +196,11 @@ void UppercaseLiteralSuffixCheck::registerMatchers(MatchFinder *Finder) {
// Sadly, we can't check whether the literal has suffix or not.
// E.g. i32 suffix still results in 'BuiltinType::Kind::Int'.
// And such an info is not stored in the *Literal itself.
- Finder->addMatcher(traverse(TK_AsIs,
+ Finder->addMatcher(
stmt(eachOf(integerLiteral().bind(IntegerLiteralCheck::Name),
floatLiteral().bind(FloatingLiteralCheck::Name)),
unless(anyOf(hasParent(userDefinedLiteral()),
- hasAncestor(isImplicit()),
- hasAncestor(substNonTypeTemplateParmExpr()))))),
+ hasAncestor(substNonTypeTemplateParmExpr())))),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
index c31fc06cb4a9e..1f6e6e6fd572c 100644
--- a/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/UppercaseLiteralSuffixCheck.h
@@ -28,6 +28,9 @@ class UppercaseLiteralSuffixCheck : 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:
template <typename LiteralType>
More information about the cfe-commits
mailing list