-
Notifications
You must be signed in to change notification settings - Fork 15.7k
[clang-tidy] Rename clang::tidy::matchers::matchesAnyListedName() to matchesAnyListedRegexName #174414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
dc82d23 to
18249a8
Compare
Member
|
@llvm/pr-subscribers-backend-x86 @llvm/pr-subscribers-clang-tidy Author: None (higher-performance) ChangesThis clarifies that patterns are regular expressions. Closes: #174229 Patch is 35.01 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/174414.diff 27 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 632f536a5b20b..6eadae21fae2f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -104,7 +104,7 @@ void AssertSideEffectCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
void AssertSideEffectCheck::registerMatchers(MatchFinder *Finder) {
auto IgnoredFunctionsMatcher =
- matchers::matchesAnyListedName(IgnoredFunctions);
+ matchers::matchesAnyListedRegexName(IgnoredFunctions);
auto DescendantWithSideEffect =
traverse(TK_AsIs, hasDescendant(expr(hasSideEffect(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
index 6aed454813a22..5adf8f97ee8f0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
@@ -85,7 +85,7 @@ void CapturingThisInMemberVariableCheck::storeOptions(
void CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) {
auto IsStdFunctionField =
fieldDecl(hasType(cxxRecordDecl(
- matchers::matchesAnyListedName(FunctionWrapperTypes))))
+ matchers::matchesAnyListedRegexName(FunctionWrapperTypes))))
.bind("field");
auto CaptureThis = lambdaCapture(anyOf(
// [this]
@@ -96,10 +96,10 @@ void CapturingThisInMemberVariableCheck::registerMatchers(MatchFinder *Finder) {
lambdaExpr(hasAnyCapture(CaptureThis)).bind("lambda");
auto IsBindCapturingThis =
- callExpr(
- callee(functionDecl(matchers::matchesAnyListedName(BindFunctions))
- .bind("callee")),
- hasAnyArgument(cxxThisExpr()))
+ callExpr(callee(functionDecl(
+ matchers::matchesAnyListedRegexName(BindFunctions))
+ .bind("callee")),
+ hasAnyArgument(cxxThisExpr()))
.bind("bind");
auto IsInitWithLambdaOrBind =
diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index 5dd2f62504c71..a2a60233d0e05 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -77,8 +77,8 @@ std::optional<TraversalKind> EmptyCatchCheck::getCheckTraversalKind() const {
}
void EmptyCatchCheck::registerMatchers(MatchFinder *Finder) {
- auto AllowedNamedExceptionDecl =
- namedDecl(matchers::matchesAnyListedName(AllowEmptyCatchForExceptions));
+ auto AllowedNamedExceptionDecl = namedDecl(
+ matchers::matchesAnyListedRegexName(AllowEmptyCatchForExceptions));
auto AllowedNamedExceptionTypes =
qualType(anyOf(hasDeclaration(AllowedNamedExceptionDecl),
references(AllowedNamedExceptionDecl),
diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
index f3e94b62f0dbd..65efb9adff3ac 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
@@ -108,7 +108,7 @@ void InvalidEnumDefaultInitializationCheck::registerMatchers(
MatchFinder *Finder) {
auto EnumWithoutZeroValue = enumType(hasDeclaration(
enumDecl(isCompleteAndHasNoZeroValue(),
- unless(matchers::matchesAnyListedName(IgnoredEnums)))
+ unless(matchers::matchesAnyListedRegexName(IgnoredEnums)))
.bind("enum")));
auto EnumOrArrayOfEnum = qualType(hasUnqualifiedDesugaredType(
anyOf(EnumWithoutZeroValue,
diff --git a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
index 127af2725cf1e..f2fc1e1832133 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NonZeroEnumToBoolConversionCheck.cpp
@@ -58,7 +58,7 @@ void NonZeroEnumToBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
hasSourceExpression(
expr(hasType(qualType(hasCanonicalType(hasDeclaration(
enumDecl(isCompleteAndHasNoZeroValue(),
- unless(matchers::matchesAnyListedName(
+ unless(matchers::matchesAnyListedRegexName(
EnumIgnoreList)))
.bind("enum"))))),
unless(declRefExpr(to(enumConstantDecl()))),
diff --git a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
index 19b4fc1c044df..c1264d03a9009 100644
--- a/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/OptionalValueConversionCheck.cpp
@@ -51,10 +51,10 @@ OptionalValueConversionCheck::getCheckTraversalKind() const {
}
void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
- auto BindOptionalType = qualType(
- hasCleanType(qualType(hasDeclaration(namedDecl(
- matchers::matchesAnyListedName(OptionalTypes))))
- .bind("optional-type")));
+ auto BindOptionalType = qualType(hasCleanType(
+ qualType(hasDeclaration(namedDecl(
+ matchers::matchesAnyListedRegexName(OptionalTypes))))
+ .bind("optional-type")));
auto EqualsBoundOptionalType =
qualType(hasCleanType(equalsBoundNode("optional-type")));
@@ -64,10 +64,11 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
cxxOperatorCallExpr(hasOverloadedOperatorName("*"),
hasUnaryOperand(hasType(EqualsBoundOptionalType)))
.bind("op-call"),
- cxxMemberCallExpr(thisPointerType(EqualsBoundOptionalType),
- callee(cxxMethodDecl(anyOf(
- hasOverloadedOperatorName("*"),
- matchers::matchesAnyListedName(ValueMethods)))))
+ cxxMemberCallExpr(
+ thisPointerType(EqualsBoundOptionalType),
+ callee(cxxMethodDecl(
+ anyOf(hasOverloadedOperatorName("*"),
+ matchers::matchesAnyListedRegexName(ValueMethods)))))
.bind("member-call")),
hasType(qualType().bind("value-type")));
@@ -78,34 +79,35 @@ void OptionalValueConversionCheck::registerMatchers(MatchFinder *Finder) {
ignoringImpCasts(anyOf(OptionalDerefMatcherImpl, StdMoveCallMatcher));
Finder->addMatcher(
- expr(anyOf(
- // construct optional
- cxxConstructExpr(argumentCountIs(1), hasType(BindOptionalType),
- hasArgument(0, OptionalDerefMatcher)),
- // known template methods in std
- callExpr(
- argumentCountIs(1),
- anyOf(
- // match std::make_unique std::make_shared
- callee(functionDecl(
- matchers::matchesAnyListedName(MakeSmartPtrList),
- hasTemplateArgument(
- 0, refersToType(BindOptionalType)))),
- // match first std::make_optional by limit argument count
- // (1) and template count (1).
- // 1. template< class T > constexpr
- // std::optional<decay_t<T>> make_optional(T&& value);
- // 2. template< class T, class... Args > constexpr
- // std::optional<T> make_optional(Args&&... args);
- callee(functionDecl(templateArgumentCountIs(1),
- hasName(MakeOptional),
- returns(BindOptionalType)))),
- hasArgument(0, OptionalDerefMatcher)),
- callExpr(argumentCountIs(1),
-
- hasArgument(0, OptionalDerefMatcher))),
- unless(anyOf(hasAncestor(typeLoc()),
- hasAncestor(expr(matchers::hasUnevaluatedContext())))))
+ expr(
+ anyOf(
+ // construct optional
+ cxxConstructExpr(argumentCountIs(1), hasType(BindOptionalType),
+ hasArgument(0, OptionalDerefMatcher)),
+ // known template methods in std
+ callExpr(
+ argumentCountIs(1),
+ anyOf(
+ // match std::make_unique std::make_shared
+ callee(functionDecl(
+ matchers::matchesAnyListedRegexName(MakeSmartPtrList),
+ hasTemplateArgument(0,
+ refersToType(BindOptionalType)))),
+ // match first std::make_optional by limit argument count
+ // (1) and template count (1).
+ // 1. template< class T > constexpr
+ // std::optional<decay_t<T>> make_optional(T&& value);
+ // 2. template< class T, class... Args > constexpr
+ // std::optional<T> make_optional(Args&&... args);
+ callee(functionDecl(templateArgumentCountIs(1),
+ hasName(MakeOptional),
+ returns(BindOptionalType)))),
+ hasArgument(0, OptionalDerefMatcher)),
+ callExpr(argumentCountIs(1),
+
+ hasArgument(0, OptionalDerefMatcher))),
+ unless(anyOf(hasAncestor(typeLoc()),
+ hasAncestor(expr(matchers::hasUnevaluatedContext())))))
.bind("expr"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
index cb379769120f4..342a6e8480fa7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousStringviewDataUsageCheck.cpp
@@ -48,9 +48,9 @@ void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) {
initListExpr(
hasType(qualType(hasCanonicalType(hasDeclaration(recordDecl()))))));
- auto DataMethod =
- cxxMethodDecl(hasName("data"),
- ofClass(matchers::matchesAnyListedName(StringViewTypes)));
+ auto DataMethod = cxxMethodDecl(
+ hasName("data"),
+ ofClass(matchers::matchesAnyListedRegexName(StringViewTypes)));
auto SizeCall = cxxMemberCallExpr(
callee(cxxMethodDecl(hasAnyName("size", "length"))),
@@ -73,13 +73,14 @@ void SuspiciousStringviewDataUsageCheck::registerMatchers(MatchFinder *Finder) {
ignoringParenImpCasts(equalsBoundNode("data-call"))),
unless(hasAnyArgument(ignoringParenImpCasts(SizeCall))),
unless(hasAnyArgument(DescendantSizeCall)),
- hasDeclaration(namedDecl(
- unless(matchers::matchesAnyListedName(AllowedCallees))))),
- initListExpr(expr().bind("parent"),
- hasType(qualType(hasCanonicalType(hasDeclaration(
- recordDecl(unless(matchers::matchesAnyListedName(
- AllowedCallees))))))),
- unless(DescendantSizeCall)))))),
+ hasDeclaration(namedDecl(unless(
+ matchers::matchesAnyListedRegexName(AllowedCallees))))),
+ initListExpr(
+ expr().bind("parent"),
+ hasType(qualType(hasCanonicalType(hasDeclaration(
+ recordDecl(unless(matchers::matchesAnyListedRegexName(
+ AllowedCallees))))))),
+ unless(DescendantSizeCall)))))),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
index 52bb355ad44d0..87d36e3c8c575 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnsafeFunctionsCheck.cpp
@@ -247,7 +247,8 @@ void UnsafeFunctionsCheck::registerMatchers(MatchFinder *Finder) {
for (const auto &Entry : CustomFunctions)
FunctionNames.emplace_back(Entry.Name);
- auto CustomFunctionsMatcher = matchers::matchesAnyListedName(FunctionNames);
+ auto CustomFunctionsMatcher =
+ matchers::matchesAnyListedRegexName(FunctionNames);
Finder->addMatcher(declRefExpr(to(functionDecl(CustomFunctionsMatcher)
.bind(CustomFunctionNamesId)))
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
index 2b7db2548cfb2..956d5048b4ee3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
@@ -69,13 +69,13 @@ void UnusedLocalNonTrivialVariableCheck::registerMatchers(MatchFinder *Finder) {
unless(isExceptionVariable()), hasLocalStorage(), isDefinition(),
unless(hasType(isReferenceType())), unless(hasType(isTrivial())),
unless(explicitMarkUnused()),
- hasType(hasUnqualifiedDesugaredType(
- anyOf(recordType(hasDeclaration(namedDecl(
- matchesAnyListedName(IncludeTypes),
- unless(matchesAnyListedName(ExcludeTypes))))),
- templateSpecializationType(hasDeclaration(namedDecl(
- matchesAnyListedName(IncludeTypes),
- unless(matchesAnyListedName(ExcludeTypes)))))))))
+ hasType(hasUnqualifiedDesugaredType(anyOf(
+ recordType(hasDeclaration(namedDecl(
+ matchesAnyListedRegexName(IncludeTypes),
+ unless(matchesAnyListedRegexName(ExcludeTypes))))),
+ templateSpecializationType(hasDeclaration(namedDecl(
+ matchesAnyListedRegexName(IncludeTypes),
+ unless(matchesAnyListedRegexName(ExcludeTypes)))))))))
.bind("var"),
this);
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
index 6fbd3922b532d..7aee725cae434 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedReturnValueCheck.cpp
@@ -171,18 +171,18 @@ void UnusedReturnValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
}
void UnusedReturnValueCheck::registerMatchers(MatchFinder *Finder) {
- auto MatchedDirectCallExpr =
- expr(callExpr(callee(functionDecl(
- // Don't match copy or move assignment operator.
- unless(isAssignmentOverloadedOperator()),
- // Don't match void overloads of checked functions.
- unless(returns(voidType())),
- anyOf(isInstantiatedFrom(matchers::matchesAnyListedName(
- CheckedFunctions)),
- returns(hasCanonicalType(hasDeclaration(
- namedDecl(matchers::matchesAnyListedName(
- CheckedReturnTypes)))))))))
- .bind("match"));
+ auto MatchedDirectCallExpr = expr(
+ callExpr(callee(functionDecl(
+ // Don't match copy or move assignment operator.
+ unless(isAssignmentOverloadedOperator()),
+ // Don't match void overloads of checked functions.
+ unless(returns(voidType())),
+ anyOf(isInstantiatedFrom(matchers::matchesAnyListedRegexName(
+ CheckedFunctions)),
+ returns(hasCanonicalType(hasDeclaration(
+ namedDecl(matchers::matchesAnyListedRegexName(
+ CheckedReturnTypes)))))))))
+ .bind("match"));
auto CheckCastToVoid =
AllowCastToVoid ? castExpr(unless(hasCastKind(CK_ToVoid))) : castExpr();
diff --git a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
index 64387024dafd6..a31dd1e5dbdcd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UseAfterMoveCheck.cpp
@@ -85,7 +85,7 @@ class UseAfterMoveFinder {
static auto getNameMatcher(llvm::ArrayRef<StringRef> InvalidationFunctions) {
return anyOf(hasAnyName("::std::move", "::std::forward"),
- matchers::matchesAnyListedName(InvalidationFunctions));
+ matchers::matchesAnyListedRegexName(InvalidationFunctions));
}
static StatementMatcher
@@ -138,11 +138,12 @@ makeReinitMatcher(const ValueDecl *MovedVariable,
hasAttr(clang::attr::Reinitializes)))),
// Functions that are specified in ReinitializationFunctions
// option.
- callExpr(callee(functionDecl(matchers::matchesAnyListedName(
- ReinitializationFunctions))),
- anyOf(cxxMemberCallExpr(on(DeclRefMatcher)),
- callExpr(unless(cxxMemberCallExpr()),
- hasArgument(0, DeclRefMatcher)))),
+ callExpr(
+ callee(functionDecl(matchers::matchesAnyListedRegexName(
+ ReinitializationFunctions))),
+ anyOf(cxxMemberCallExpr(on(DeclRefMatcher)),
+ callExpr(unless(cxxMemberCallExpr()),
+ hasArgument(0, DeclRefMatcher)))),
// Passing variable to a function as a non-const pointer.
callExpr(forEachArgumentWithParam(
unaryOperator(hasOperatorName("&"),
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
index 8ecbccda3c5f2..ee3a45c171e32 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/NoSuspendWithLockCheck.cpp
@@ -24,7 +24,7 @@ void NoSuspendWithLockCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
void NoSuspendWithLockCheck::registerMatchers(MatchFinder *Finder) {
auto LockType = templateSpecializationType(
- hasDeclaration(namedDecl(matchers::matchesAnyListedName(
+ hasDeclaration(namedDecl(matchers::matchesAnyListedRegexName(
utils::options::parseStringList(LockGuards)))));
const StatementMatcher Lock =
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
index cf4b445a554e8..73f43d3cd3b1a 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp
@@ -95,7 +95,7 @@ void ProBoundsAvoidUncheckedContainerAccessCheck::registerMatchers(
cxxMethodDecl(
hasOverloadedOperatorName("[]"),
anyOf(parameterCountIs(0), parameterCountIs(1)),
- unless(matchers::ma...
[truncated]
|
zeyi2
reviewed
Jan 6, 2026
18249a8 to
6ca88ea
Compare
…tedRegexName to clarify that patterns are regular expressions Closes llvm#174229
6ca88ea to
a92ff21
Compare
vbvictor
approved these changes
Jan 7, 2026
zeyi2
approved these changes
Jan 7, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This clarifies that patterns are regular expressions.
Closes: #174229