[ASTMatchers] Add type matcher for SubstTemplateTypeParmType.

llvm-svn: 246037
This commit is contained in:
Samuel Benzaquen 2015-08-26 16:15:59 +00:00
parent 446fe8d62c
commit f8ec454f7d
3 changed files with 27 additions and 0 deletions

View 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.
///

View 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);

View 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()));