Skip to content

Commit

Permalink
[clang] Add a matcher for template template parameters.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
riccibruno committed Aug 11, 2020
1 parent e2f3240 commit f4dccf1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Expand Up @@ -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.
///
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/ASTMatchers/ASTMatchersInternal.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions clang/lib/ASTMatchers/Dynamic/Registry.cpp
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit f4dccf1

Please sign in to comment.