forked from OSchip/llvm-project
[ASTMatchers] Add type matcher for SubstTemplateTypeParmType.
llvm-svn: 246037
This commit is contained in:
parent
446fe8d62c
commit
f8ec454f7d
|
@ -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.
|
||||
///
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()));
|
||||
|
|
Loading…
Reference in New Issue