]> granicus.if.org Git - clang/commitdiff
[ASTMatchers] Add type matcher for SubstTemplateTypeParmType.
authorSamuel Benzaquen <sbenza@google.com>
Wed, 26 Aug 2015 16:15:59 +0000 (16:15 +0000)
committerSamuel Benzaquen <sbenza@google.com>
Wed, 26 Aug 2015 16:15:59 +0000 (16:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246037 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersTest.cpp

index cd80bab8dbee4f8ecd1e24d1b41cb86c2cc1c852..46f30f06d5a93159c3bd43d2ad3ec3f66b247092 100644 (file)
@@ -3936,6 +3936,20 @@ AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
   return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
 }
 
+/// \brief Matches types that represent the result of substituting a type for a
+/// template type parameter.
+///
+/// Given
+/// \code
+///   template <typename T>
+///   void F(T t) {
+///     int i = 1 + t;
+///   }
+/// \code
+///
+/// \c substTemplateTypeParmType() matches the type of 't' but not '1'
+AST_TYPE_MATCHER(SubstTemplateTypeParmType, substTemplateTypeParmType);
+
 /// \brief Matches declarations whose declaration context, interpreted as a
 /// Decl, matches \c InnerMatcher.
 ///
index 19cad2554b5713d50fa0603e4976b28d0f481860..1544b08434451ad359b77f4f8460c97c5e5289b7 100644 (file)
@@ -327,6 +327,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(stmt);
   REGISTER_MATCHER(stringLiteral);
   REGISTER_MATCHER(substNonTypeTemplateParmExpr);
+  REGISTER_MATCHER(substTemplateTypeParmType);
   REGISTER_MATCHER(switchCase);
   REGISTER_MATCHER(switchStmt);
   REGISTER_MATCHER(templateArgument);
index c04f0fb82d4376dc9a9813cff7612db39993bed4..5bc66f6c0306c8e0aa5972f7aefb277dcd594742 100644 (file)
@@ -4331,6 +4331,18 @@ TEST(ElaboratedTypeNarrowing, namesType) {
     elaboratedType(elaboratedType(namesType(typedefType())))));
 }
 
+TEST(TypeMatching, MatchesSubstTemplateTypeParmType) {
+  const std::string code = "template <typename T>"
+                           "int F() {"
+                           "  return 1 + T();"
+                           "}"
+                           "int i = F<int>();";
+  EXPECT_FALSE(matches(code, binaryOperator(hasLHS(
+                                 expr(hasType(substTemplateTypeParmType()))))));
+  EXPECT_TRUE(matches(code, binaryOperator(hasRHS(
+                                expr(hasType(substTemplateTypeParmType()))))));
+}
+
 TEST(NNS, MatchesNestedNameSpecifiers) {
   EXPECT_TRUE(matches("namespace ns { struct A {}; } ns::A a;",
                       nestedNameSpecifier()));