From: Eric Fiselier Date: Sat, 17 Oct 2015 02:34:44 +0000 (+0000) Subject: Add an AST node matcher for TemplateTypeParmDecl objects. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6af718e79b12438448ffde082409bd683d16f5e0;p=clang Add an AST node matcher for TemplateTypeParmDecl objects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250602 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index 10b7339165..1f681e7f9a 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -321,7 +321,7 @@ namespaceDecl() Given template <typename T, int N> struct C {}; -templateArgument() +nonTypeTemplateParmDecl() matches 'N', but not 'T'. @@ -371,6 +371,16 @@ in +Matcher<Decl>templateTypeParmDeclMatcher<TemplateTypeParmDecl>... +
Matches template type parameter declarations.
+
+Given
+  template <typename T, int N> struct C {};
+templateTypeParmDecl()
+  matches 'T', but not 'N'.
+
+ + Matcher<Decl>translationUnitDeclMatcher<TranslationUnitDecl>...
Matches the top declaration context.
 
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index 3c827cd659..484cc943ea 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -418,12 +418,24 @@ const internal::VariadicAllOfMatcher templateArgument;
 /// \code
 ///   template  struct C {};
 /// \endcode
-/// templateArgument()
+/// nonTypeTemplateParmDecl()
 ///   matches 'N', but not 'T'.
 const internal::VariadicDynCastAllOfMatcher<
   Decl,
   NonTypeTemplateParmDecl> nonTypeTemplateParmDecl;
 
+/// \brief Matches template type parameter declarations.
+///
+/// Given
+/// \code
+///   template  struct C {};
+/// \endcode
+/// templateTypeParmDecl()
+///   matches 'T', but not 'N'.
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  TemplateTypeParmDecl> templateTypeParmDecl;
+
 /// \brief Matches public C++ declarations.
 ///
 /// Given
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 828e71b35c..f671cd14cd 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1179,6 +1179,13 @@ TEST(Matcher, NonTypeTemplateParmDecl) {
       notMatches("template  void f();", nonTypeTemplateParmDecl()));
 }
 
+TEST(Matcher, templateTypeParmDecl) {
+  EXPECT_TRUE(matches("template  void f();",
+                      templateTypeParmDecl(hasName("T"))));
+  EXPECT_TRUE(
+      notMatches("template  void f();", templateTypeParmDecl()));
+}
+
 TEST(Matcher, UserDefinedLiteral) {
   EXPECT_TRUE(matches("constexpr char operator \"\" _inc (const char i) {"
                       "  return i + 1;"