From: Aaron Ballman Date: Mon, 5 Oct 2015 19:44:42 +0000 (+0000) Subject: Adding an AST node matcher for NonTypeTemplateParmDecl objects. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9fc9d8db3d9c2601a1f9f3df9263e9094d22a0e8;p=clang Adding an AST node matcher for NonTypeTemplateParmDecl objects. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@249341 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index cab709e3a6..0d6d18d60e 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -316,6 +316,16 @@ namespaceDecl() +Matcher<Decl>nonTypeTemplateParmDeclMatcher<NonTypeTemplateParmDecl>... +
Matches non-type template parameter declarations.
+
+Given
+  template <typename T, int N> struct C {};
+templateArgument()
+  matches 'N', but not 'T'.
+
+ + Matcher<Decl>objcInterfaceDeclMatcher<ObjCInterfaceDecl>...
Matches Objective-C interface declarations.
 
@@ -2213,7 +2223,7 @@ Usable as: Matcher<FunctionDecl>isVariadic
 
Matches if a function declaration is variadic.
 
-Example matches f, but not g or h. The function i will not match, event when
+Example matches f, but not g or h. The function i will not match, even when
 compiled in C mode.
   void f(...);
   void g(int);
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index cfed1fd16d..8b97df6ce6 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -412,6 +412,18 @@ const internal::VariadicAllOfMatcher cxxCtorInitializer;
 ///   matches 'int' in C.
 const internal::VariadicAllOfMatcher templateArgument;
 
+/// \brief Matches non-type template parameter declarations.
+///
+/// Given
+/// \code
+///   template  struct C {};
+/// \endcode
+/// templateArgument()
+///   matches 'N', but not 'T'.
+const internal::VariadicDynCastAllOfMatcher<
+  Decl,
+  NonTypeTemplateParmDecl> nonTypeTemplateParmDecl;
+
 /// \brief Matches public C++ declarations.
 ///
 /// Given
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index a15d6ac2be..4954402e83 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1172,6 +1172,13 @@ TEST(Matcher, SubstNonTypeTemplateParm) {
                       substNonTypeTemplateParmExpr()));
 }
 
+TEST(Matcher, NonTypeTemplateParmDecl) {
+  EXPECT_TRUE(matches("template  void f();",
+                      nonTypeTemplateParmDecl(hasName("N"))));
+  EXPECT_TRUE(
+      notMatches("template  void f();", nonTypeTemplateParmDecl()));
+}
+
 TEST(Matcher, UserDefinedLiteral) {
   EXPECT_TRUE(matches("constexpr char operator \"\" _inc (const char i) {"
                       "  return i + 1;"