[clang] Add a matcher for template template parameters.

There are already matchers for type template parameters and non-type template
parameters, but somehow no matcher exists for template template parameters
and I need it to write unit tests.

Differential Revision: https://reviews.llvm.org/D85536

Reviewed By: aaron.ballman
This commit is contained in:
Bruno Ricci 2020-08-11 15:54:15 +01:00
parent e2f3240472
commit f4dccf115c
No known key found for this signature in database
GPG Key ID: D58C906B2F684D92
4 changed files with 25 additions and 0 deletions

View File

@ -562,6 +562,18 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl,
extern const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;
/// Matches template template parameter declarations.
///
/// Given
/// \code
/// template <template <typename> class Z, int N> struct C {};
/// \endcode
/// templateTypeParmDecl()
/// matches 'Z', but not 'N'.
extern const internal::VariadicDynCastAllOfMatcher<Decl,
TemplateTemplateParmDecl>
templateTemplateParmDecl;
/// Matches public C++ declarations and C++ base specifers that specify public
/// inheritance.
///

View File

@ -740,6 +740,9 @@ const internal::VariadicDynCastAllOfMatcher<Decl, NonTypeTemplateParmDecl>
nonTypeTemplateParmDecl;
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTypeParmDecl>
templateTypeParmDecl;
const internal::VariadicDynCastAllOfMatcher<Decl, TemplateTemplateParmDecl>
templateTemplateParmDecl;
const internal::VariadicAllOfMatcher<QualType> qualType;
const internal::VariadicAllOfMatcher<Type> type;
const internal::VariadicAllOfMatcher<TypeLoc> typeLoc;

View File

@ -514,6 +514,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(templateArgumentCountIs);
REGISTER_MATCHER(templateName);
REGISTER_MATCHER(templateSpecializationType);
REGISTER_MATCHER(templateTemplateParmDecl);
REGISTER_MATCHER(templateTypeParmDecl);
REGISTER_MATCHER(templateTypeParmType);
REGISTER_MATCHER(throughUsingDecl);

View File

@ -408,6 +408,15 @@ TEST_P(ASTMatchersTest, TemplateTypeParmDecl) {
EXPECT_TRUE(notMatches("template <int N> void f();", templateTypeParmDecl()));
}
TEST_P(ASTMatchersTest, TemplateTemplateParmDecl) {
if (!GetParam().isCXX())
return;
EXPECT_TRUE(matches("template <template <typename> class Z> void f();",
templateTemplateParmDecl(hasName("Z"))));
EXPECT_TRUE(notMatches("template <typename, int> void f();",
templateTemplateParmDecl()));
}
TEST_P(ASTMatchersTest, UserDefinedLiteral) {
if (!GetParam().isCXX11OrLater()) {
return;