Skip to content

Commit 4326f68

Browse files
authored
[ASTMatchers][NFC] Replace makeMatcher function with CTAD (#147197)
C++17's CTAD obsoletes `makeMatcher` (and many `make*` functions like it). The deduction guide is written out explicitly to avoid `-Wctad-maybe-unsupported` warnings.
1 parent b717568 commit 4326f68

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

clang-tools-extra/clang-tidy/utils/Matchers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class MatchesAnyListedNameMatcher
145145
// qualified name will be used for matching, otherwise its name will be used.
146146
inline ::clang::ast_matchers::internal::Matcher<NamedDecl>
147147
matchesAnyListedName(llvm::ArrayRef<StringRef> NameList) {
148-
return ::clang::ast_matchers::internal::makeMatcher(
148+
return ::clang::ast_matchers::internal::Matcher(
149149
new MatchesAnyListedNameMatcher(NameList));
150150
}
151151

@@ -188,7 +188,7 @@ class MatchesAnyListedTypeNameMatcher
188188
inline ::clang::ast_matchers::internal::Matcher<QualType>
189189
matchesAnyListedTypeName(llvm::ArrayRef<StringRef> NameList,
190190
bool CanonicalTypes) {
191-
return ::clang::ast_matchers::internal::makeMatcher(
191+
return ::clang::ast_matchers::internal::Matcher(
192192
new MatchesAnyListedTypeNameMatcher(NameList, CanonicalTypes));
193193
}
194194
inline ::clang::ast_matchers::internal::Matcher<QualType>

clang/include/clang/ASTMatchers/ASTMatchersInternal.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,13 @@ class Matcher {
672672
DynTypedMatcher Implementation;
673673
}; // class Matcher
674674

675-
/// A convenient helper for creating a Matcher<T> without specifying
676-
/// the template type argument.
675+
// Deduction guide for Matcher.
676+
template <typename T> Matcher(MatcherInterface<T> *) -> Matcher<T>;
677+
678+
// TODO: Remove in LLVM 23.
677679
template <typename T>
680+
[[deprecated(
681+
"Use CTAD constructor instead, 'makeMatcher' will be removed in LLVM 23.")]]
678682
inline Matcher<T> makeMatcher(MatcherInterface<T> *Implementation) {
679683
return Matcher<T>(Implementation);
680684
}

clang/include/clang/ASTMatchers/ASTMatchersMacros.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
}; \
107107
} \
108108
inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher() { \
109-
return ::clang::ast_matchers::internal::makeMatcher( \
109+
return ::clang::ast_matchers::internal::Matcher( \
110110
new internal::matcher_##DefineMatcher##Matcher()); \
111111
} \
112112
inline bool internal::matcher_##DefineMatcher##Matcher::matches( \
@@ -150,7 +150,7 @@
150150
} \
151151
inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
152152
ParamType const &Param) { \
153-
return ::clang::ast_matchers::internal::makeMatcher( \
153+
return ::clang::ast_matchers::internal::Matcher( \
154154
new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param)); \
155155
} \
156156
typedef ::clang::ast_matchers::internal::Matcher<Type> ( \
@@ -200,7 +200,7 @@
200200
} \
201201
inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
202202
ParamType1 const &Param1, ParamType2 const &Param2) { \
203-
return ::clang::ast_matchers::internal::makeMatcher( \
203+
return ::clang::ast_matchers::internal::Matcher( \
204204
new internal::matcher_##DefineMatcher##OverloadId##Matcher(Param1, \
205205
Param2)); \
206206
} \
@@ -476,7 +476,7 @@
476476
} \
477477
inline ::clang::ast_matchers::internal::Matcher<Type> DefineMatcher( \
478478
llvm::StringRef Param, llvm::Regex::RegexFlags RegexFlags) { \
479-
return ::clang::ast_matchers::internal::makeMatcher( \
479+
return ::clang::ast_matchers::internal::Matcher( \
480480
new internal::matcher_##DefineMatcher##OverloadId##Matcher( \
481481
::clang::ast_matchers::internal::createAndVerifyRegex( \
482482
Param, RegexFlags, #DefineMatcher))); \

clang/lib/Tooling/Transformer/RewriteRule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ template <typename T>
258258
ast_matchers::internal::Matcher<T>
259259
forEachDescendantDynamically(ast_matchers::BoundNodes Nodes,
260260
DynTypedMatcher M) {
261-
return ast_matchers::internal::makeMatcher(new BindingsMatcher<T>(
261+
return ast_matchers::internal::Matcher(new BindingsMatcher<T>(
262262
std::move(Nodes),
263-
ast_matchers::internal::makeMatcher(
263+
ast_matchers::internal::Matcher(
264264
new DynamicForEachDescendantMatcher<T>(std::move(M)))));
265265
}
266266

0 commit comments

Comments
 (0)