[clang-tools-extra] 11a411a - Revert "[clang-tidy][NFC] Remove duplicated code"
Piotr Zegar via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 31 08:07:05 PDT 2024
Author: Piotr Zegar
Date: 2024-03-31T15:06:49Z
New Revision: 11a411a49b62c129bba551df4587dd446fcdc660
URL: https://github.com/llvm/llvm-project/commit/11a411a49b62c129bba551df4587dd446fcdc660
DIFF: https://github.com/llvm/llvm-project/commit/11a411a49b62c129bba551df4587dd446fcdc660.diff
LOG: Revert "[clang-tidy][NFC] Remove duplicated code"
This reverts commit b6f6be4b500ff64c23a5103ac3311cb74519542f.
Added:
Modified:
clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
clang-tools-extra/clang-tidy/utils/LexerUtils.h
clang-tools-extra/clang-tidy/utils/Matchers.h
clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
Removed:
clang-tools-extra/clang-tidy/objc/ObjcMatcher.h
################################################################################
diff --git a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
index b20d1b1fa7e32f..1eef86ddc00b95 100644
--- a/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
+++ b/clang-tools-extra/clang-tidy/abseil/AbseilMatcher.h
@@ -6,9 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
-
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include <algorithm>
@@ -60,5 +57,3 @@ AST_POLYMORPHIC_MATCHER(
}
} // namespace clang::ast_matchers
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_ABSEIL_ABSEILMATCHER_H
diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
index 448bb4b7e1f941..6cb687de4dc86e 100644
--- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryFloatCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "DurationFactoryFloatCheck.h"
-#include "../utils/LexerUtils.h"
#include "DurationRewriter.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -19,6 +18,15 @@ using namespace clang::ast_matchers;
namespace clang::tidy::abseil {
+// Returns `true` if `Range` is inside a macro definition.
+static bool insideMacroDefinition(const MatchFinder::MatchResult &Result,
+ SourceRange Range) {
+ return !clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(Range),
+ *Result.SourceManager, Result.Context->getLangOpts())
+ .isValid();
+}
+
void DurationFactoryFloatCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(callee(functionDecl(DurationFactoryFunction())),
@@ -37,9 +45,7 @@ void DurationFactoryFloatCheck::check(const MatchFinder::MatchResult &Result) {
const auto *MatchedCall = Result.Nodes.getNodeAs<CallExpr>("call");
// Don't try and replace things inside of macro definitions.
- if (tidy::utils::lexer::insideMacroDefinition(MatchedCall->getSourceRange(),
- *Result.SourceManager,
- Result.Context->getLangOpts()))
+ if (insideMacroDefinition(Result, MatchedCall->getSourceRange()))
return;
const Expr *Arg = MatchedCall->getArg(0)->IgnoreImpCasts();
diff --git a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
index 687171e4c782d9..28b2f81fdc8c84 100644
--- a/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/StringFindStrContainsCheck.cpp
@@ -30,15 +30,12 @@ using ::clang::transformer::makeRule;
using ::clang::transformer::node;
using ::clang::transformer::RewriteRuleWith;
-namespace {
-
AST_MATCHER(Type, isCharType) { return Node.isCharType(); }
-} // namespace
-static const char StringLikeClassesDefault[] = "::std::basic_string;"
+static const char DefaultStringLikeClasses[] = "::std::basic_string;"
"::std::basic_string_view;"
"::absl::string_view";
-static const char AbseilStringsMatchHeaderDefault[] = "absl/strings/match.h";
+static const char DefaultAbseilStringsMatchHeader[] = "absl/strings/match.h";
static transformer::RewriteRuleWith<std::string>
makeRewriteRule(ArrayRef<StringRef> StringLikeClassNames,
@@ -87,9 +84,9 @@ StringFindStrContainsCheck::StringFindStrContainsCheck(
StringRef Name, ClangTidyContext *Context)
: TransformerClangTidyCheck(Name, Context),
StringLikeClassesOption(utils::options::parseStringList(
- Options.get("StringLikeClasses", StringLikeClassesDefault))),
+ Options.get("StringLikeClasses", DefaultStringLikeClasses))),
AbseilStringsMatchHeaderOption(Options.get(
- "AbseilStringsMatchHeader", AbseilStringsMatchHeaderDefault)) {
+ "AbseilStringsMatchHeader", DefaultAbseilStringsMatchHeader)) {
setRule(
makeRewriteRule(StringLikeClassesOption, AbseilStringsMatchHeaderOption));
}
diff --git a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
index ecf9a2293c9a8c..a2171aad32b739 100644
--- a/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/TimeSubtractionCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "TimeSubtractionCheck.h"
-#include "../utils/LexerUtils.h"
#include "DurationRewriter.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -19,6 +18,15 @@ using namespace clang::ast_matchers;
namespace clang::tidy::abseil {
+// Returns `true` if `Range` is inside a macro definition.
+static bool insideMacroDefinition(const MatchFinder::MatchResult &Result,
+ SourceRange Range) {
+ return !clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(Range),
+ *Result.SourceManager, Result.Context->getLangOpts())
+ .isValid();
+}
+
static bool isConstructorAssignment(const MatchFinder::MatchResult &Result,
const Expr *Node) {
// For C++14 and earlier there are elidable constructors that must be matched
@@ -122,9 +130,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *BinOp = Result.Nodes.getNodeAs<BinaryOperator>("binop");
std::string InverseName =
Result.Nodes.getNodeAs<FunctionDecl>("func_decl")->getNameAsString();
- if (tidy::utils::lexer::insideMacroDefinition(BinOp->getSourceRange(),
- *Result.SourceManager,
- Result.Context->getLangOpts()))
+ if (insideMacroDefinition(Result, BinOp->getSourceRange()))
return;
std::optional<DurationScale> Scale = getScaleForTimeInverse(InverseName);
@@ -133,9 +139,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *OuterCall = Result.Nodes.getNodeAs<CallExpr>("outer_call");
if (OuterCall) {
- if (tidy::utils::lexer::insideMacroDefinition(
- OuterCall->getSourceRange(), *Result.SourceManager,
- Result.Context->getLangOpts()))
+ if (insideMacroDefinition(Result, OuterCall->getSourceRange()))
return;
// We're working with the first case of matcher, and need to replace the
@@ -161,9 +165,7 @@ void TimeSubtractionCheck::check(const MatchFinder::MatchResult &Result) {
.bind("arg"))),
*BinOp, *Result.Context));
if (MaybeCallArg && MaybeCallArg->getArg(0)->IgnoreImpCasts() == BinOp &&
- !tidy::utils::lexer::insideMacroDefinition(
- MaybeCallArg->getSourceRange(), *Result.SourceManager,
- Result.Context->getLangOpts())) {
+ !insideMacroDefinition(Result, MaybeCallArg->getSourceRange())) {
// Handle the case where the matched expression is inside a call which
// converts it from the inverse to a Duration. In this case, we replace
// the outer with just the subtraction expression, which gives the right
diff --git a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
index 323d966711ddcf..8e27e8e3e0c2be 100644
--- a/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/abseil/UpgradeDurationConversionsCheck.cpp
@@ -139,8 +139,8 @@ void UpgradeDurationConversionsCheck::check(
// We gather source locations from template matches not in template
// instantiations for future matches.
- auto IsInsideTemplate = stmt(
- hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl()))));
+ internal::Matcher<Stmt> IsInsideTemplate =
+ hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
if (!match(IsInsideTemplate, *ArgExpr, *Result.Context).empty())
MatchedTemplateLocations.insert(Loc);
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
index 939c311b56b351..8c13ce5a90e9b5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -25,13 +25,15 @@ void BadSignalToKillThreadCheck::registerMatchers(MatchFinder *Finder) {
this);
}
+static Preprocessor *PP;
+
void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
const auto IsSigterm = [](const auto &KeyValue) -> bool {
return KeyValue.first->getName() == "SIGTERM" &&
KeyValue.first->hasMacroDefinition();
};
const auto TryExpandAsInteger =
- [this](Preprocessor::macro_iterator It) -> std::optional<unsigned> {
+ [](Preprocessor::macro_iterator It) -> std::optional<unsigned> {
if (It == PP->macro_end())
return std::nullopt;
const MacroInfo *MI = PP->getMacroInfo(It->first);
@@ -62,8 +64,8 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
}
void BadSignalToKillThreadCheck::registerPPCallbacks(
- const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) {
- this->PP = PP;
+ const SourceManager &SM, Preprocessor *Pp, Preprocessor *ModuleExpanderPP) {
+ PP = Pp;
}
} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h
index 17580e744be9dc..f21b8c09eb0c6d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.h
@@ -26,10 +26,7 @@ class BadSignalToKillThreadCheck : public ClangTidyCheck {
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
-
-private:
std::optional<unsigned> SigtermValue;
- Preprocessor *PP = nullptr;
};
} // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 2c56a39bbeb104..93f35cb2c1a3d7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -15,8 +15,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
-namespace {
-
AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
const Expr *Init = Node.getInit();
if (Init && !Init->isValueDependent()) {
@@ -27,8 +25,6 @@ AST_MATCHER(clang::VarDecl, hasConstantDeclaration) {
return false;
}
-} // namespace
-
DynamicStaticInitializersCheck::DynamicStaticInitializersCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index 6e7c017aca893d..84e99c7fafc74b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -1881,8 +1881,6 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
} // namespace filter
-namespace {
-
/// Matches functions that have at least the specified amount of parameters.
AST_MATCHER_P(FunctionDecl, parameterCountGE, unsigned, N) {
return Node.getNumParams() >= N;
@@ -1905,8 +1903,6 @@ AST_MATCHER(FunctionDecl, isOverloadedUnaryOrBinaryOperator) {
}
}
-} // namespace
-
/// Returns the DefaultMinimumLength if the Value of requested minimum length
/// is less than 2. Minimum lengths of 0 or 1 are not accepted.
static inline unsigned clampMinimumLength(const unsigned Value) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index 3c64479249a970..ff5b885aa95f81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -20,7 +20,7 @@ using ::clang::ast_matchers::internal::Matcher;
namespace clang::tidy::bugprone {
namespace {
-AST_MATCHER(CXXCatchStmt, isCatchInMacro) {
+AST_MATCHER(CXXCatchStmt, isInMacro) {
return Node.getBeginLoc().isMacroID() || Node.getEndLoc().isMacroID() ||
Node.getCatchLoc().isMacroID();
}
@@ -89,8 +89,7 @@ void EmptyCatchCheck::registerMatchers(MatchFinder *Finder) {
hasCanonicalType(AllowedNamedExceptionTypes)));
Finder->addMatcher(
- cxxCatchStmt(unless(isExpansionInSystemHeader()),
- unless(isCatchInMacro()),
+ cxxCatchStmt(unless(isExpansionInSystemHeader()), unless(isInMacro()),
unless(hasCaughtType(IgnoredExceptionType)),
hasHandler(compoundStmt(
statementCountIs(0),
diff --git a/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
index d6645a0e91c172..9b3b01eb026833 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncDecInConditionsCheck.cpp
@@ -15,7 +15,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
-namespace {
AST_MATCHER(BinaryOperator, isLogicalOperator) { return Node.isLogicalOp(); }
AST_MATCHER(UnaryOperator, isUnaryPrePostOperator) {
@@ -27,8 +26,6 @@ AST_MATCHER(CXXOperatorCallExpr, isPrePostOperator) {
Node.getOperator() == OO_MinusMinus;
}
-} // namespace
-
void IncDecInConditionsCheck::registerMatchers(MatchFinder *Finder) {
auto OperatorMatcher = expr(
anyOf(binaryOperator(anyOf(isComparisonOperator(), isLogicalOperator())),
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index b91c585489c78a..e329588290cd4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -33,11 +33,11 @@ AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
} // namespace ast_matchers
namespace tidy::bugprone {
-static ast_matchers::internal::Matcher<Stmt>
-loopEndingStmt(ast_matchers::internal::Matcher<Stmt> Internal) {
- ast_matchers::internal::Matcher<QualType> isNoReturnFunType =
+static internal::Matcher<Stmt>
+loopEndingStmt(internal::Matcher<Stmt> Internal) {
+ internal::Matcher<QualType> isNoReturnFunType =
ignoringParens(functionType(typeHasNoReturnAttr()));
- ast_matchers::internal::Matcher<Decl> isNoReturnDecl =
+ internal::Matcher<Decl> isNoReturnDecl =
anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
varDecl(hasType(blockPointerType(pointee(isNoReturnFunType)))));
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
index becfdc5ee6e977..41191a3cfed23a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "MultipleNewInOneExpressionCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Lex/Lexer.h"
@@ -52,6 +51,29 @@ bool isExprValueStored(const Expr *E, ASTContext &C) {
} // namespace
+AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
+ ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
+ for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const CXXCatchStmt *CatchS = Node.getHandler(I);
+ // Check for generic catch handler (match anything).
+ if (CatchS->getCaughtType().isNull())
+ return true;
+ ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+ if (InnerMatcher.matches(CatchS->getCaughtType(), Finder, &Result)) {
+ *Builder = std::move(Result);
+ return true;
+ }
+ }
+ return false;
+}
+
+AST_MATCHER(CXXNewExpr, mayThrow) {
+ FunctionDecl *OperatorNew = Node.getOperatorNew();
+ if (!OperatorNew)
+ return false;
+ return !OperatorNew->getType()->castAs<FunctionProtoType>()->isNothrow();
+}
+
void MultipleNewInOneExpressionCheck::registerMatchers(MatchFinder *Finder) {
auto BadAllocType =
recordType(hasDeclaration(cxxRecordDecl(hasName("::std::bad_alloc"))));
@@ -63,10 +85,9 @@ void MultipleNewInOneExpressionCheck::registerMatchers(MatchFinder *Finder) {
auto CatchBadAllocType =
qualType(hasCanonicalType(anyOf(BadAllocType, BadAllocReferenceType,
ExceptionType, ExceptionReferenceType)));
- auto BadAllocCatchingTryBlock =
- cxxTryStmt(matchers::hasHandlerFor(CatchBadAllocType));
+ auto BadAllocCatchingTryBlock = cxxTryStmt(hasHandlerFor(CatchBadAllocType));
- auto NewExprMayThrow = cxxNewExpr(matchers::mayThrow());
+ auto NewExprMayThrow = cxxNewExpr(mayThrow());
auto HasNewExpr1 = expr(anyOf(NewExprMayThrow.bind("new1"),
hasDescendant(NewExprMayThrow.bind("new1"))));
auto HasNewExpr2 = expr(anyOf(NewExprMayThrow.bind("new2"),
@@ -94,7 +115,7 @@ void MultipleNewInOneExpressionCheck::registerMatchers(MatchFinder *Finder) {
hasAncestor(BadAllocCatchingTryBlock)),
this);
Finder->addMatcher(
- cxxNewExpr(matchers::mayThrow(),
+ cxxNewExpr(mayThrow(),
hasDescendant(NewExprMayThrow.bind("new2_in_new1")),
hasAncestor(BadAllocCatchingTryBlock))
.bind("new1"),
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp
index 5746a1f3b358d2..de05cc0e4f7fb5 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleStatementMacroCheck.cpp
@@ -16,13 +16,10 @@ namespace clang::tidy::bugprone {
namespace {
-AST_MATCHER(Expr, isExprInMacro) { return Node.getBeginLoc().isMacroID(); }
-
-} // namespace
+AST_MATCHER(Expr, isInMacro) { return Node.getBeginLoc().isMacroID(); }
/// Find the next statement after `S`.
-static const Stmt *nextStmt(const MatchFinder::MatchResult &Result,
- const Stmt *S) {
+const Stmt *nextStmt(const MatchFinder::MatchResult &Result, const Stmt *S) {
auto Parents = Result.Context->getParents(*S);
if (Parents.empty())
return nullptr;
@@ -43,8 +40,8 @@ using ExpansionRanges = std::vector<SourceRange>;
/// \brief Get all the macro expansion ranges related to `Loc`.
///
/// The result is ordered from most inner to most outer.
-static ExpansionRanges
-getExpansionRanges(SourceLocation Loc, const MatchFinder::MatchResult &Result) {
+ExpansionRanges getExpansionRanges(SourceLocation Loc,
+ const MatchFinder::MatchResult &Result) {
ExpansionRanges Locs;
while (Loc.isMacroID()) {
Locs.push_back(
@@ -54,9 +51,10 @@ getExpansionRanges(SourceLocation Loc, const MatchFinder::MatchResult &Result) {
return Locs;
}
+} // namespace
+
void MultipleStatementMacroCheck::registerMatchers(MatchFinder *Finder) {
- const auto Inner =
- expr(isExprInMacro(), unless(compoundStmt())).bind("inner");
+ const auto Inner = expr(isInMacro(), unless(compoundStmt())).bind("inner");
Finder->addMatcher(
stmt(anyOf(ifStmt(hasThen(Inner)), ifStmt(hasElse(Inner)).bind("else"),
whileStmt(hasBody(Inner)), forStmt(hasBody(Inner))))
diff --git a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
index 93412c213bbdf0..902490f4d33c13 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp
@@ -322,12 +322,12 @@ SourceRange getSourceRangeOfStmt(const Stmt *S, ASTContext &Ctx) {
return P.getSourceRange();
}
+} // namespace
+
AST_MATCHER(FunctionDecl, isStandardFunction) {
return isStandardFunction(&Node);
}
-} // namespace
-
SignalHandlerCheck::SignalHandlerCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index 77cc9f39d302e3..a1cffbc6661992 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -17,6 +17,10 @@ namespace clang::tidy::bugprone {
namespace {
+AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
+ return Node.getValue().ugt(N);
+}
+
AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,
ast_matchers::internal::Matcher<Expr>, InnerMatcher) {
if (Depth < 0)
@@ -44,15 +48,15 @@ AST_MATCHER_P2(Expr, hasSizeOfDescendant, int, Depth,
return false;
}
-} // namespace
-
-static CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
+CharUnits getSizeOfType(const ASTContext &Ctx, const Type *Ty) {
if (!Ty || Ty->isIncompleteType() || Ty->isDependentType() ||
isa<DependentSizedArrayType>(Ty) || !Ty->isConstantSizeType())
return CharUnits::Zero();
return Ctx.getTypeSizeInChars(Ty);
}
+} // namespace
+
SizeofExpressionCheck::SizeofExpressionCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
@@ -179,11 +183,10 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
// Detect expression like: sizeof(expr) <= k for a suspicious constant 'k'.
if (WarnOnSizeOfCompareToConstant) {
Finder->addMatcher(
- binaryOperator(
- matchers::isRelationalOperator(),
- hasOperands(ignoringParenImpCasts(SizeOfExpr),
- ignoringParenImpCasts(integerLiteral(anyOf(
- equals(0), matchers::isBiggerThan(0x80000))))))
+ binaryOperator(matchers::isRelationalOperator(),
+ hasOperands(ignoringParenImpCasts(SizeOfExpr),
+ ignoringParenImpCasts(integerLiteral(anyOf(
+ equals(0), isBiggerThan(0x80000))))))
.bind("sizeof-compare-constant"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
index 11d105e23fca4a..8ae4351ac2830a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "StringConstructorCheck.h"
-#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -17,7 +16,12 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
-static const char DefaultStringNames[] =
+namespace {
+AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
+ return Node.getValue().getZExtValue() > N;
+}
+
+const char DefaultStringNames[] =
"::std::basic_string;::std::basic_string_view";
static std::vector<StringRef>
@@ -32,6 +36,8 @@ removeNamespaces(const std::vector<StringRef> &Names) {
return Result;
}
+} // namespace
+
StringConstructorCheck::StringConstructorCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
@@ -55,7 +61,7 @@ void StringConstructorCheck::registerMatchers(MatchFinder *Finder) {
unaryOperator(hasOperatorName("-"),
hasUnaryOperand(integerLiteral(unless(equals(0)))))));
const auto LargeLengthExpr = expr(ignoringParenImpCasts(
- integerLiteral(matchers::isBiggerThan(LargeLengthThreshold))));
+ integerLiteral(isBiggerThan(LargeLengthThreshold))));
const auto CharPtrType = type(anyOf(pointerType(), arrayType()));
// Match a string-literal; even through a declaration with initializer.
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
index 155dced4a136c5..b160e7259905ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnhandledExceptionAtNewCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "UnhandledExceptionAtNewCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -15,6 +14,29 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
+AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
+ ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
+ for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const CXXCatchStmt *CatchS = Node.getHandler(I);
+ // Check for generic catch handler (match anything).
+ if (CatchS->getCaughtType().isNull())
+ return true;
+ ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+ if (InnerMatcher.matches(CatchS->getCaughtType(), Finder, &Result)) {
+ *Builder = std::move(Result);
+ return true;
+ }
+ }
+ return false;
+}
+
+AST_MATCHER(CXXNewExpr, mayThrow) {
+ FunctionDecl *OperatorNew = Node.getOperatorNew();
+ if (!OperatorNew)
+ return false;
+ return !OperatorNew->getType()->castAs<FunctionProtoType>()->isNothrow();
+}
+
UnhandledExceptionAtNewCheck::UnhandledExceptionAtNewCheck(
StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context) {}
@@ -30,12 +52,11 @@ void UnhandledExceptionAtNewCheck::registerMatchers(MatchFinder *Finder) {
auto CatchBadAllocType =
qualType(hasCanonicalType(anyOf(BadAllocType, BadAllocReferenceType,
ExceptionType, ExceptionReferenceType)));
- auto BadAllocCatchingTryBlock =
- cxxTryStmt(matchers::hasHandlerFor(CatchBadAllocType));
+ auto BadAllocCatchingTryBlock = cxxTryStmt(hasHandlerFor(CatchBadAllocType));
auto FunctionMayNotThrow = functionDecl(isNoThrow());
- Finder->addMatcher(cxxNewExpr(matchers::mayThrow(),
+ Finder->addMatcher(cxxNewExpr(mayThrow(),
unless(hasAncestor(BadAllocCatchingTryBlock)),
hasAncestor(FunctionMayNotThrow))
.bind("new-expr"),
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index bd73a7cac3781c..bebdce525e2887 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "VirtualNearMissCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -18,6 +17,8 @@ using namespace clang::ast_matchers;
namespace clang::tidy::bugprone {
namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
return Node.isOverloadedOperator();
}
@@ -215,8 +216,8 @@ void VirtualNearMissCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxMethodDecl(
unless(anyOf(isOverride(), isImplicit(), cxxConstructorDecl(),
- cxxDestructorDecl(), cxxConversionDecl(),
- matchers::isStaticMethod(), isOverloadedOperator())))
+ cxxDestructorDecl(), cxxConversionDecl(), isStatic(),
+ isOverloadedOperator())))
.bind("method"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
index d933c043da64fa..3923df312791db 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeVarargCheck.cpp
@@ -20,9 +20,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::cppcoreguidelines {
-const clang::ast_matchers::internal::VariadicDynCastAllOfMatcher<Stmt,
- VAArgExpr>
- VAArgExpr;
+const internal::VariadicDynCastAllOfMatcher<Stmt, VAArgExpr> VAArgExpr;
static constexpr StringRef AllowedVariadics[] = {
// clang-format off
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
index a93b603099b88c..aa70b3896f16dd 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/VirtualClassDestructorCheck.cpp
@@ -18,7 +18,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::cppcoreguidelines {
-namespace {
AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor) {
// We need to call Node.getDestructor() instead of matching a
// CXXDestructorDecl. Otherwise, tests will fail for class templates, since
@@ -34,7 +33,6 @@ AST_MATCHER(CXXRecordDecl, hasPublicVirtualOrProtectedNonVirtualDestructor) {
!Destructor->isVirtual()));
}
-} // namespace
void VirtualClassDestructorCheck::registerMatchers(MatchFinder *Finder) {
ast_matchers::internal::Matcher<CXXRecordDecl> InheritsVirtualMethod =
hasAnyBase(hasType(cxxRecordDecl(has(cxxMethodDecl(isVirtual())))));
diff --git a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
index c7590b51523245..805dcaf3ce4025 100644
--- a/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/UpgradeGoogletestCaseCheck.cpp
@@ -234,7 +234,7 @@ static bool isInInstantiation(const NodeType &Node,
template <typename NodeType>
static bool isInTemplate(const NodeType &Node,
const MatchFinder::MatchResult &Result) {
- ast_matchers::internal::Matcher<NodeType> IsInsideTemplate =
+ internal::Matcher<NodeType> IsInsideTemplate =
hasAncestor(decl(anyOf(classTemplateDecl(), functionTemplateDecl())));
return !match(IsInsideTemplate, Node, *Result.Context).empty();
}
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h b/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
index 77d4bd0a254141..7d4120085b8667 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
+++ b/clang-tools-extra/clang-tidy/llvmlibc/NamespaceConstants.h
@@ -6,9 +6,6 @@
//
//===----------------------------------------------------------------------===//
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACE_CONSTANTS_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACE_CONSTANTS_H
-
#include "llvm/ADT/StringRef.h"
namespace clang::tidy::llvm_libc {
@@ -17,5 +14,3 @@ const static llvm::StringRef RequiredNamespaceStart = "__llvm_libc";
const static llvm::StringRef RequiredNamespaceMacroName = "LIBC_NAMESPACE";
} // namespace clang::tidy::llvm_libc
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVMLIBC_NAMESPACE_CONSTANTS_H
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
index 517288930fa88e..89790ea70cf229 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidCArraysCheck.cpp
@@ -20,6 +20,14 @@ AST_MATCHER(clang::TypeLoc, hasValidBeginLoc) {
return Node.getBeginLoc().isValid();
}
+AST_MATCHER_P(clang::TypeLoc, hasType,
+ clang::ast_matchers::internal::Matcher<clang::Type>,
+ InnerMatcher) {
+ const clang::Type *TypeNode = Node.getTypePtr();
+ return TypeNode != nullptr &&
+ InnerMatcher.matches(*TypeNode, Finder, Builder);
+}
+
AST_MATCHER(clang::RecordDecl, isExternCContext) {
return Node.isExternCContext();
}
@@ -51,7 +59,7 @@ void AvoidCArraysCheck::registerMatchers(MatchFinder *Finder) {
unless(parmVarDecl())))));
Finder->addMatcher(
- typeLoc(hasValidBeginLoc(), loc(arrayType()),
+ typeLoc(hasValidBeginLoc(), hasType(arrayType()),
unless(anyOf(hasParent(parmVarDecl(isArgvOfMain())),
hasParent(varDecl(isExternC())),
hasParent(fieldDecl(
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 9b05c3a7425c50..3229e302eb4322 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -94,7 +94,7 @@ static StatementMatcher incrementVarMatcher() {
}
static StatementMatcher
-arrayConditionMatcher(ast_matchers::internal::Matcher<Expr> LimitExpr) {
+arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
return binaryOperator(
anyOf(allOf(hasOperatorName("<"), hasLHS(integerComparisonMatcher()),
hasRHS(LimitExpr)),
@@ -209,7 +209,7 @@ StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
// This matcher tests that a declaration is a CXXRecordDecl that has an
// overloaded operator*(). If the operator*() returns by value instead of by
// reference then the return type is tagged with DerefByValueResultName.
- ast_matchers::internal::Matcher<VarDecl> TestDerefReturnsByValue =
+ internal::Matcher<VarDecl> TestDerefReturnsByValue =
hasType(hasUnqualifiedDesugaredType(
recordType(hasDeclaration(cxxRecordDecl(hasMethod(cxxMethodDecl(
hasOverloadedOperatorName("*"),
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index dc8a87b8ae0fdf..aec67808846b12 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "UseAutoCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/TypeLoc.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -21,7 +20,6 @@ using namespace clang::ast_matchers;
using namespace clang::ast_matchers::internal;
namespace clang::tidy::modernize {
-
namespace {
const char IteratorDeclStmtId[] = "iterator_decl";
@@ -157,6 +155,14 @@ Matcher<NamedDecl> hasStdContainerName() {
return hasAnyName(ContainerNames);
}
+/// Matches declaration reference or member expressions with explicit template
+/// arguments.
+AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
+ AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
+ MemberExpr)) {
+ return Node.hasExplicitTemplateArgs();
+}
+
/// Returns a DeclarationMatcher that matches standard iterators nested
/// inside records with a standard container name.
DeclarationMatcher standardIterator() {
@@ -232,9 +238,9 @@ StatementMatcher makeDeclWithTemplateCastMatcher() {
auto ST =
substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg")));
- auto ExplicitCall = anyOf(
- has(memberExpr(matchers::hasExplicitTemplateArgs())),
- has(ignoringImpCasts(declRefExpr(matchers::hasExplicitTemplateArgs()))));
+ auto ExplicitCall =
+ anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+ has(ignoringImpCasts(declRefExpr(hasExplicitTemplateArgs()))));
auto TemplateArg =
hasTemplateArgument(0, refersToType(qualType().bind("arg")));
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
index c477e566c78782..430455a38f395e 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -7,9 +7,7 @@
//===----------------------------------------------------------------------===//
#include "UseEmplaceCheck.h"
-#include "../utils/Matchers.h"
#include "../utils/OptionsUtils.h"
-
using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
@@ -80,6 +78,10 @@ AST_MATCHER(CXXMemberCallExpr, hasSameNumArgsAsDeclNumParams) {
return Node.getNumArgs() == Node.getMethodDecl()->getNumParams();
}
+AST_MATCHER(DeclRefExpr, hasExplicitTemplateArgs) {
+ return Node.hasExplicitTemplateArgs();
+}
+
// Helper Matcher which applies the given QualType Matcher either directly or by
// resolving a pointer type to its pointee. Used to match v.push_back() as well
// as p->push_back().
@@ -219,7 +221,7 @@ void UseEmplaceCheck::registerMatchers(MatchFinder *Finder) {
auto MakeTuple = ignoringImplicit(
callExpr(callee(expr(ignoringImplicit(declRefExpr(
- unless(matchers::hasExplicitTemplateArgs()),
+ unless(hasExplicitTemplateArgs()),
to(functionDecl(hasAnyName(TupleMakeFunctions))))))))
.bind("make"));
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
index 406be8c66be764..5134eb51a03226 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
@@ -48,8 +48,8 @@ static std::set<const Type *> getAllDirectBases(const CXXRecordDecl *Record) {
/// Returns a matcher that matches member expressions where the base is
/// the variable declared as \p Var and the accessed member is the one declared
/// as \p Field.
-ast_matchers::internal::Matcher<Expr> accessToFieldInVar(const FieldDecl *Field,
- const ValueDecl *Var) {
+internal::Matcher<Expr> accessToFieldInVar(const FieldDecl *Field,
+ const ValueDecl *Var) {
return ignoringImpCasts(
memberExpr(hasObjectExpression(declRefExpr(to(varDecl(equalsNode(Var))))),
member(fieldDecl(equalsNode(Field)))));
diff --git a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
index 9fdd60ead04042..9561cc71183d97 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseEqualsDeleteCheck.cpp
@@ -16,7 +16,6 @@ using namespace clang::ast_matchers;
namespace clang::tidy::modernize {
namespace {
-
AST_MATCHER(FunctionDecl, hasAnyDefinition) {
if (Node.hasBody() || Node.isPureVirtual() || Node.isDefaulted() ||
Node.isDeleted())
@@ -42,6 +41,9 @@ AST_MATCHER(CXXMethodDecl, isSpecialFunction) {
}
} // namespace
+static const char SpecialFunction[] = "SpecialFunction";
+static const char DeletedNotPublic[] = "DeletedNotPublic";
+
UseEqualsDeleteCheck::UseEqualsDeleteCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
@@ -61,17 +63,17 @@ void UseEqualsDeleteCheck::registerMatchers(MatchFinder *Finder) {
// defined.
unless(ofClass(hasMethod(cxxMethodDecl(unless(PrivateSpecialFn),
unless(hasAnyDefinition()))))))
- .bind("SpecialFunction"),
+ .bind(SpecialFunction),
this);
Finder->addMatcher(
- cxxMethodDecl(isDeleted(), unless(isPublic())).bind("DeletedNotPublic"),
+ cxxMethodDecl(isDeleted(), unless(isPublic())).bind(DeletedNotPublic),
this);
}
void UseEqualsDeleteCheck::check(const MatchFinder::MatchResult &Result) {
if (const auto *Func =
- Result.Nodes.getNodeAs<CXXMethodDecl>("SpecialFunction")) {
+ Result.Nodes.getNodeAs<CXXMethodDecl>(SpecialFunction)) {
SourceLocation EndLoc = Lexer::getLocForEndOfToken(
Func->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
@@ -82,7 +84,7 @@ void UseEqualsDeleteCheck::check(const MatchFinder::MatchResult &Result) {
"use '= delete' to prohibit calling of a special member function")
<< FixItHint::CreateInsertion(EndLoc, " = delete");
} else if (const auto *Func =
- Result.Nodes.getNodeAs<CXXMethodDecl>("DeletedNotPublic")) {
+ Result.Nodes.getNodeAs<CXXMethodDecl>(DeletedNotPublic)) {
// Ignore this warning in macros, since it's extremely noisy in code using
// DISALLOW_COPY_AND_ASSIGN-style macros and there's no easy way to
// automatically fix the warning when macros are in play.
diff --git a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
index 225a1e7bedea43..2223a1999f736b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
@@ -62,7 +62,7 @@ void UseTransparentFunctorsCheck::registerMatchers(MatchFinder *Finder) {
this);
}
-static const StringRef MessageDiag = "prefer transparent functors '%0<>'";
+static const StringRef Message = "prefer transparent functors '%0<>'";
template <typename T> static T getInnerTypeLocAs(TypeLoc Loc) {
T Result;
@@ -79,7 +79,7 @@ void UseTransparentFunctorsCheck::check(
Result.Nodes.getNodeAs<ClassTemplateSpecializationDecl>("FunctorClass");
if (const auto *FuncInst =
Result.Nodes.getNodeAs<CXXConstructExpr>("FuncInst")) {
- diag(FuncInst->getBeginLoc(), MessageDiag) << FuncClass->getName();
+ diag(FuncInst->getBeginLoc(), Message) << FuncClass->getName();
return;
}
@@ -117,9 +117,9 @@ void UseTransparentFunctorsCheck::check(
SourceLocation ReportLoc = FunctorLoc.getLocation();
if (ReportLoc.isInvalid())
return;
- diag(ReportLoc, MessageDiag)
- << FuncClass->getName()
- << FixItHint::CreateRemoval(FunctorTypeLoc.getArgLoc(0).getSourceRange());
+ diag(ReportLoc, Message) << FuncClass->getName()
+ << FixItHint::CreateRemoval(
+ FunctorTypeLoc.getArgLoc(0).getSourceRange());
}
} // namespace clang::tidy::modernize
diff --git a/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp b/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
index 103268caf32c8e..42f383edc67eda 100644
--- a/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/MissingHashCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "MissingHashCheck.h"
-#include "ObjcMatcher.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -17,6 +16,12 @@ namespace clang::tidy::objc {
namespace {
+AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
+ ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
+ const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface();
+ return Base.matches(*InterfaceDecl, Finder, Builder);
+}
+
AST_MATCHER_P(ObjCContainerDecl, hasInstanceMethod,
ast_matchers::internal::Matcher<ObjCMethodDecl>, Base) {
// Check each instance method against the provided matcher.
diff --git a/clang-tools-extra/clang-tidy/objc/ObjcMatcher.h b/clang-tools-extra/clang-tidy/objc/ObjcMatcher.h
deleted file mode 100644
index f272b5b0f8a648..00000000000000
--- a/clang-tools-extra/clang-tidy/objc/ObjcMatcher.h
+++ /dev/null
@@ -1,40 +0,0 @@
-//===- AbseilMatcher.h - clang-tidy ---------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCMATCHER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCMATCHER_H
-
-#include "clang/AST/ASTContext.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-
-namespace clang::ast_matchers {
-
-/// Matches Objective-C implementations with interfaces that match
-/// \c Base.
-///
-/// Example matches implementation declarations for X.
-/// (matcher = objcImplementationDecl(hasInterface(hasName("X"))))
-/// \code
-/// @interface X
-/// @end
-/// @implementation X
-/// @end
-/// @interface Y
-// @end
-/// @implementation Y
-/// @end
-/// \endcode
-AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
- ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
- const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface();
- return Base.matches(*InterfaceDecl, Finder, Builder);
-}
-
-} // namespace clang::ast_matchers
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBJC_OBJCMATCHER_H
diff --git a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
index 572a1463e5c02d..951cbc52c9a994 100644
--- a/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/objc/SuperSelfCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "SuperSelfCheck.h"
-#include "ObjcMatcher.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -33,6 +32,27 @@ AST_MATCHER(ObjCMethodDecl, isInitializer) {
return Node.getMethodFamily() == OMF_init;
}
+/// Matches Objective-C implementations with interfaces that match
+/// \c Base.
+///
+/// Example matches implementation declarations for X.
+/// (matcher = objcImplementationDecl(hasInterface(hasName("X"))))
+/// \code
+/// @interface X
+/// @end
+/// @implementation X
+/// @end
+/// @interface Y
+// @end
+/// @implementation Y
+/// @end
+/// \endcode
+AST_MATCHER_P(ObjCImplementationDecl, hasInterface,
+ ast_matchers::internal::Matcher<ObjCInterfaceDecl>, Base) {
+ const ObjCInterfaceDecl *InterfaceDecl = Node.getClassInterface();
+ return Base.matches(*InterfaceDecl, Finder, Builder);
+}
+
/// Matches Objective-C message expressions where the receiver is the
/// super instance.
///
diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
index 8c38bad593a376..9beb185cba929d 100644
--- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
+++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp
@@ -232,7 +232,7 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization(
Options.get("ExcludedContainerTypes", ""))) {}
void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) {
- auto LocalVarCopiedFrom = [this](const auto &CopyCtorArg) {
+ auto LocalVarCopiedFrom = [this](const internal::Matcher<Expr> &CopyCtorArg) {
return compoundStmt(
forEachDescendant(
declStmt(
diff --git a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
index 5b1bf0108cbb79..1284df6bd99cfd 100644
--- a/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ConvertMemberFunctionsToStatic.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "ConvertMemberFunctionsToStatic.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/RecursiveASTVisitor.h"
@@ -19,12 +18,40 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
-namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
AST_MATCHER(CXXMethodDecl, isOverloadedOperator) {
return Node.isOverloadedOperator();
}
+AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
+ return Node.hasAnyDependentBases();
+}
+
+AST_MATCHER(CXXMethodDecl, isTemplate) {
+ return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
+}
+
+AST_MATCHER(CXXMethodDecl, isDependentContext) {
+ return Node.isDependentContext();
+}
+
+AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
+ const ASTContext &Ctxt = Finder->getASTContext();
+ return clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(
+ Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+ Ctxt.getSourceManager(), Ctxt.getLangOpts())
+ .isInvalid();
+}
+
+AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
+ ast_matchers::internal::Matcher<CXXMethodDecl>, InnerMatcher) {
+ return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
+}
+
AST_MATCHER(CXXMethodDecl, usesThis) {
class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
public:
@@ -47,27 +74,22 @@ AST_MATCHER(CXXMethodDecl, usesThis) {
return UsageOfThis.Used;
}
-} // namespace
-
void ConvertMemberFunctionsToStatic::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
cxxMethodDecl(
isDefinition(), isUserProvided(),
unless(anyOf(
- isExpansionInSystemHeader(), isVirtual(),
- matchers::isStaticMethod(), matchers::hasTrivialBody(),
- isOverloadedOperator(), cxxConstructorDecl(), cxxDestructorDecl(),
- cxxConversionDecl(), matchers::isTemplate(),
- matchers::isDependentContext(),
+ isExpansionInSystemHeader(), isVirtual(), isStatic(),
+ hasTrivialBody(), isOverloadedOperator(), cxxConstructorDecl(),
+ cxxDestructorDecl(), cxxConversionDecl(), isTemplate(),
+ isDependentContext(),
ofClass(anyOf(
isLambda(),
- matchers::hasAnyDependentBases()) // Method might become
- // virtual depending on
- // template base class.
+ hasAnyDependentBases()) // Method might become virtual
+ // depending on template base class.
),
- matchers::isInsideMacroDefinition(),
- matchers::hasCanonicalDecl(matchers::isInsideMacroDefinition()),
- usesThis())))
+ isInsideMacroDefinition(),
+ hasCanonicalDecl(isInsideMacroDefinition()), usesThis())))
.bind("x"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
index 261c02ea2d53c9..759cdd44fd6581 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -202,9 +202,9 @@ void CognitiveComplexity::account(SourceLocation Loc, unsigned short Nesting,
Total += Increase;
}
-class CognitiveComplexityFunctionASTVisitor final
- : public RecursiveASTVisitor<CognitiveComplexityFunctionASTVisitor> {
- using Base = RecursiveASTVisitor<CognitiveComplexityFunctionASTVisitor>;
+class FunctionASTVisitor final
+ : public RecursiveASTVisitor<FunctionASTVisitor> {
+ using Base = RecursiveASTVisitor<FunctionASTVisitor>;
// If set to true, macros are ignored during analysis.
const bool IgnoreMacros;
@@ -219,7 +219,7 @@ class CognitiveComplexityFunctionASTVisitor final
std::stack<OBO, SmallVector<OBO, 4>> BinaryOperatorsStack;
public:
- explicit CognitiveComplexityFunctionASTVisitor(const bool IgnoreMacros)
+ explicit FunctionASTVisitor(const bool IgnoreMacros)
: IgnoreMacros(IgnoreMacros) {}
bool traverseStmtWithIncreasedNestingLevel(Stmt *Node) {
@@ -453,13 +453,12 @@ class CognitiveComplexityFunctionASTVisitor final
// The parameter MainAnalyzedFunction is needed to
diff erentiate between the
// cases where TraverseDecl() is the entry point from
// FunctionCognitiveComplexityCheck::check() and the cases where it was called
- // from the CognitiveComplexityFunctionASTVisitor itself. Explanation: if we
- // get a function definition (e.g. constructor, destructor, method), the
- // Cognitive Complexity specification states that the Nesting level shall be
- // increased. But if this function is the entry point, then the Nesting level
- // should not be increased. Thus that parameter is there and is used to
- // fall-through directly to traversing if this is the main function that is
- // being analyzed.
+ // from the FunctionASTVisitor itself. Explanation: if we get a function
+ // definition (e.g. constructor, destructor, method), the Cognitive Complexity
+ // specification states that the Nesting level shall be increased. But if this
+ // function is the entry point, then the Nesting level should not be
+ // increased. Thus that parameter is there and is used to fall-through
+ // directly to traversing if this is the main function that is being analyzed.
bool TraverseDecl(Decl *Node, bool MainAnalyzedFunction = false) {
if (!Node || MainAnalyzedFunction)
return Base::TraverseDecl(Node);
@@ -516,7 +515,7 @@ void FunctionCognitiveComplexityCheck::registerMatchers(MatchFinder *Finder) {
void FunctionCognitiveComplexityCheck::check(
const MatchFinder::MatchResult &Result) {
- CognitiveComplexityFunctionASTVisitor Visitor(IgnoreMacros);
+ FunctionASTVisitor Visitor(IgnoreMacros);
SourceLocation Loc;
const auto *TheDecl = Result.Nodes.getNodeAs<FunctionDecl>("func");
diff --git a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
index c828ef3bc78b4d..d42fcba70e81b4 100644
--- a/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/MakeMemberFunctionConstCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "MakeMemberFunctionConstCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/ParentMapContext.h"
#include "clang/AST/RecursiveASTVisitor.h"
@@ -18,6 +17,36 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+
+AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
+
+AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
+ return Node.hasAnyDependentBases();
+}
+
+AST_MATCHER(CXXMethodDecl, isTemplate) {
+ return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
+}
+
+AST_MATCHER(CXXMethodDecl, isDependentContext) {
+ return Node.isDependentContext();
+}
+
+AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
+ const ASTContext &Ctxt = Finder->getASTContext();
+ return clang::Lexer::makeFileCharRange(
+ clang::CharSourceRange::getCharRange(
+ Node.getTypeSourceInfo()->getTypeLoc().getSourceRange()),
+ Ctxt.getSourceManager(), Ctxt.getLangOpts())
+ .isInvalid();
+}
+
+AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
+ ast_matchers::internal::Matcher<CXXMethodDecl>, InnerMatcher) {
+ return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
+}
+
enum UsageKind { Unused, Const, NonConst };
class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
@@ -176,7 +205,6 @@ class FindUsageOfThis : public RecursiveASTVisitor<FindUsageOfThis> {
}
};
-namespace {
AST_MATCHER(CXXMethodDecl, usesThisAsConst) {
FindUsageOfThis UsageOfThis(Finder->getASTContext());
@@ -186,8 +214,6 @@ AST_MATCHER(CXXMethodDecl, usesThisAsConst) {
return UsageOfThis.Usage == Const;
}
-} // namespace
-
void MakeMemberFunctionConstCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
traverse(
@@ -196,18 +222,15 @@ void MakeMemberFunctionConstCheck::registerMatchers(MatchFinder *Finder) {
isDefinition(), isUserProvided(),
unless(anyOf(
isExpansionInSystemHeader(), isVirtual(), isConst(),
- matchers::isStaticMethod(), matchers::hasTrivialBody(),
- cxxConstructorDecl(), cxxDestructorDecl(),
- matchers::isTemplate(), matchers::isDependentContext(),
- ofClass(anyOf(
- isLambda(),
- matchers::hasAnyDependentBases()) // Method might become
+ isStatic(), hasTrivialBody(), cxxConstructorDecl(),
+ cxxDestructorDecl(), isTemplate(), isDependentContext(),
+ ofClass(anyOf(isLambda(),
+ hasAnyDependentBases()) // Method might become
// virtual depending on
// template base class.
),
- matchers::isInsideMacroDefinition(),
- matchers::hasCanonicalDecl(
- matchers::isInsideMacroDefinition()))),
+ isInsideMacroDefinition(),
+ hasCanonicalDecl(isInsideMacroDefinition()))),
usesThisAsConst())
.bind("x")),
this);
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
index bfd4dca11e947a..7850a6f29995f6 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
@@ -15,13 +15,10 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
-namespace {
AST_MATCHER(FunctionDecl, doesDeclarationForceExternallyVisibleDefinition) {
return Node.doesDeclarationForceExternallyVisibleDefinition();
}
-} // namespace
-
RedundantDeclarationCheck::RedundantDeclarationCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
index 86d3c7e860c9d4..8837ac16e88281 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantSmartptrGetCheck.cpp
@@ -15,8 +15,7 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
namespace {
-clang::ast_matchers::internal::Matcher<Expr>
-callToGet(const clang::ast_matchers::internal::Matcher<Decl> &OnClass) {
+internal::Matcher<Expr> callToGet(const internal::Matcher<Decl> &OnClass) {
return expr(
anyOf(cxxMemberCallExpr(
on(expr(anyOf(hasType(OnClass),
@@ -44,7 +43,7 @@ callToGet(const clang::ast_matchers::internal::Matcher<Decl> &OnClass) {
.bind("redundant_get");
}
-clang::ast_matchers::internal::Matcher<Decl> knownSmartptr() {
+internal::Matcher<Decl> knownSmartptr() {
return recordDecl(hasAnyName("::std::unique_ptr", "::std::shared_ptr"));
}
diff --git a/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
index 9abe0f0e155ace..587ae8ea305802 100644
--- a/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ReferenceToConstructedTemporaryCheck.cpp
@@ -20,8 +20,7 @@ namespace {
// Predicate structure to check if lifetime of temporary is not extended by
// ValueDecl pointed out by ID
struct NotExtendedByDeclBoundToPredicate {
- bool
- operator()(const clang::ast_matchers::internal::BoundNodesMap &Nodes) const {
+ bool operator()(const internal::BoundNodesMap &Nodes) const {
const auto *Other = Nodes.getNodeAs<ValueDecl>(ID);
if (!Other)
return true;
diff --git a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
index 77b8f5e5ac2169..65356cc3929c54 100644
--- a/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.cpp
@@ -7,7 +7,6 @@
//===----------------------------------------------------------------------===//
#include "StaticAccessedThroughInstanceCheck.h"
-#include "../utils/Matchers.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "llvm/ADT/StringRef.h"
@@ -16,6 +15,10 @@ using namespace clang::ast_matchers;
namespace clang::tidy::readability {
+namespace {
+AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); }
+} // namespace
+
static unsigned getNameSpecifierNestingLevel(const QualType &QType) {
if (const auto *ElType = QType->getAs<ElaboratedType>()) {
if (const NestedNameSpecifier *NestedSpecifiers = ElType->getQualifier()) {
@@ -39,7 +42,7 @@ void StaticAccessedThroughInstanceCheck::storeOptions(
void StaticAccessedThroughInstanceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
- memberExpr(hasDeclaration(anyOf(cxxMethodDecl(matchers::isStaticMethod()),
+ memberExpr(hasDeclaration(anyOf(cxxMethodDecl(isStatic()),
varDecl(hasStaticStorageDuration()),
enumConstantDecl())))
.bind("memberExpression"),
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
index 8ee148a5bb3922..df2b0bef576ca3 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.cpp
@@ -285,11 +285,4 @@ SourceLocation getLocationForNoexceptSpecifier(const FunctionDecl *FuncDecl,
return {};
}
-bool insideMacroDefinition(SourceRange Range, const SourceManager &SM,
- const LangOptions &LangOpts) {
- return clang::Lexer::makeFileCharRange(
- clang::CharSourceRange::getCharRange(Range), SM, LangOpts)
- .isInvalid();
-}
-
} // namespace clang::tidy::utils::lexer
diff --git a/clang-tools-extra/clang-tidy/utils/LexerUtils.h b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
index a697e7ee8adf11..ea9bd512b68b8f 100644
--- a/clang-tools-extra/clang-tidy/utils/LexerUtils.h
+++ b/clang-tools-extra/clang-tidy/utils/LexerUtils.h
@@ -125,11 +125,6 @@ SourceLocation getUnifiedEndLoc(const Stmt &S, const SourceManager &SM,
SourceLocation getLocationForNoexceptSpecifier(const FunctionDecl *FuncDecl,
const SourceManager &SM);
-// Returns true if a part of the range resides inside a macro expansion or the
-// range does not reside on the same FileID.
-bool insideMacroDefinition(SourceRange Range, const SourceManager &SM,
- const LangOptions &LangOpts);
-
} // namespace tidy::utils::lexer
} // namespace clang
diff --git a/clang-tools-extra/clang-tidy/utils/Matchers.h b/clang-tools-extra/clang-tidy/utils/Matchers.h
index dc47bb515e0ef1..045e3ffbb6a8b4 100644
--- a/clang-tools-extra/clang-tidy/utils/Matchers.h
+++ b/clang-tools-extra/clang-tidy/utils/Matchers.h
@@ -9,7 +9,6 @@
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_UTILS_MATCHERS_H
-#include "LexerUtils.h"
#include "TypeTraits.h"
#include "clang/AST/ExprConcepts.h"
#include "clang/ASTMatchers/ASTMatchers.h"
@@ -23,10 +22,6 @@ AST_MATCHER(BinaryOperator, isRelationalOperator) {
AST_MATCHER(BinaryOperator, isEqualityOperator) { return Node.isEqualityOp(); }
-AST_MATCHER_P(IntegerLiteral, isBiggerThan, unsigned, N) {
- return Node.getValue().getZExtValue() > N;
-}
-
AST_MATCHER(QualType, isExpensiveToCopy) {
std::optional<bool> IsExpensive =
utils::type_traits::isExpensiveToCopy(Node, Finder->getASTContext());
@@ -42,67 +37,6 @@ AST_MATCHER(QualType, isTriviallyDestructible) {
return utils::type_traits::isTriviallyDestructible(Node);
}
-AST_MATCHER(CXXRecordDecl, hasAnyDependentBases) {
- return Node.hasAnyDependentBases();
-}
-
-AST_MATCHER(CXXMethodDecl, isStaticMethod) { return Node.isStatic(); }
-
-AST_MATCHER(CXXMethodDecl, hasTrivialBody) { return Node.hasTrivialBody(); }
-
-AST_MATCHER(CXXMethodDecl, isTemplate) {
- return Node.getTemplatedKind() != FunctionDecl::TK_NonTemplate;
-}
-
-AST_MATCHER(CXXMethodDecl, isDependentContext) {
- return Node.isDependentContext();
-}
-
-AST_MATCHER(CXXMethodDecl, isInsideMacroDefinition) {
- const ASTContext &Ctxt = Finder->getASTContext();
- return utils::lexer::insideMacroDefinition(
- Node.getTypeSourceInfo()->getTypeLoc().getSourceRange(),
- Ctxt.getSourceManager(), Ctxt.getLangOpts());
-}
-
-AST_MATCHER_P(CXXMethodDecl, hasCanonicalDecl,
- ast_matchers::internal::Matcher<CXXMethodDecl>, InnerMatcher) {
- return InnerMatcher.matches(*Node.getCanonicalDecl(), Finder, Builder);
-}
-
-AST_MATCHER(CXXNewExpr, mayThrow) {
- FunctionDecl *OperatorNew = Node.getOperatorNew();
- if (!OperatorNew)
- return false;
- if (auto *FuncType = OperatorNew->getType()->getAs<FunctionProtoType>())
- return !FuncType->isNothrow();
- return false;
-}
-
-AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
- ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
- for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
- const CXXCatchStmt *CatchS = Node.getHandler(I);
- // Check for generic catch handler (match anything).
- if (CatchS->getCaughtType().isNull())
- return true;
- ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
- if (InnerMatcher.matches(CatchS->getCaughtType(), Finder, &Result)) {
- *Builder = std::move(Result);
- return true;
- }
- }
- return false;
-}
-
-// Matches declaration reference or member expressions with explicit template
-// arguments.
-AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
- MemberExpr)) {
- return Node.hasExplicitTemplateArgs();
-}
-
// Returns QualType matcher for references to const.
AST_MATCHER_FUNCTION(ast_matchers::TypeMatcher, isReferenceToConst) {
using namespace ast_matchers;
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
index 214f0fd43a621b..4703ce12698190 100644
--- a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.cpp
@@ -13,23 +13,18 @@
#include "clang/ASTMatchers/ASTMatchers.h"
#include "clang/Lex/Lexer.h"
#include <optional>
-
namespace clang::tidy::utils {
using namespace ast_matchers;
-namespace {
+NamespaceAliaser::NamespaceAliaser(const SourceManager &SourceMgr)
+ : SourceMgr(SourceMgr) {}
AST_MATCHER_P(NamespaceAliasDecl, hasTargetNamespace,
ast_matchers::internal::Matcher<NamespaceDecl>, innerMatcher) {
return innerMatcher.matches(*Node.getNamespace(), Finder, Builder);
}
-} // namespace
-
-NamespaceAliaser::NamespaceAliaser(const SourceManager &SourceMgr)
- : SourceMgr(SourceMgr) {}
-
std::optional<FixItHint>
NamespaceAliaser::createAlias(ASTContext &Context, const Stmt &Statement,
StringRef Namespace,
More information about the cfe-commits
mailing list