diff options
author | Martin Bohme <mboehme@google.com> | 2016-08-09 15:07:52 +0000 |
---|---|---|
committer | Martin Bohme <mboehme@google.com> | 2016-08-09 15:07:52 +0000 |
commit | e8aa1a2a0be336b5975327433851a7a807d420bf (patch) | |
tree | 7fbab59291298f3a80159dd97d3822d87032a3ee /unittests/ASTMatchers | |
parent | ecf27f00beed659c1978fedb10d731204ea32781 (diff) |
[ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()
Summary: Required for D22220
Reviewers: sbenza, klimek, aaron.ballman, alexfh
Subscribers: alexfh, klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D23004
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278123 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/ASTMatchers')
-rw-r--r-- | unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 41d588f122..fcd3dcb5af 100644 --- a/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp @@ -241,6 +241,21 @@ TEST(HasDeclaration, HasDeclarationOfTemplateSpecializationType) { hasDeclaration(namedDecl(hasName("A")))))))); } +TEST(HasUnderlyingDecl, Matches) { + EXPECT_TRUE(matches("namespace N { template <class T> void f(T t); }" + "template <class T> void g() { using N::f; f(T()); }", + unresolvedLookupExpr(hasAnyDeclaration( + namedDecl(hasUnderlyingDecl(hasName("::N::f"))))))); + EXPECT_TRUE(matches( + "namespace N { template <class T> void f(T t); }" + "template <class T> void g() { N::f(T()); }", + unresolvedLookupExpr(hasAnyDeclaration(namedDecl(hasName("::N::f")))))); + EXPECT_TRUE(notMatches( + "namespace N { template <class T> void f(T t); }" + "template <class T> void g() { using N::f; f(T()); }", + unresolvedLookupExpr(hasAnyDeclaration(namedDecl(hasName("::N::f")))))); +} + TEST(HasType, TakesQualTypeMatcherAndMatchesExpr) { TypeMatcher ClassX = hasDeclaration(recordDecl(hasName("X"))); EXPECT_TRUE( @@ -2072,5 +2087,24 @@ TEST(Matcher, ForEachOverriden) { EXPECT_TRUE(notMatches(Code2, ForEachOverriddenInClass("A1"))); } +TEST(Matcher, HasAnyDeclaration) { + std::string Fragment = "void foo(int p1);" + "void foo(int *p2);" + "void bar(int p3);" + "template <typename T> void baz(T t) { foo(t); }"; + + EXPECT_TRUE( + matches(Fragment, unresolvedLookupExpr(hasAnyDeclaration(functionDecl( + hasParameter(0, parmVarDecl(hasName("p1")))))))); + EXPECT_TRUE( + matches(Fragment, unresolvedLookupExpr(hasAnyDeclaration(functionDecl( + hasParameter(0, parmVarDecl(hasName("p2")))))))); + EXPECT_TRUE( + notMatches(Fragment, unresolvedLookupExpr(hasAnyDeclaration(functionDecl( + hasParameter(0, parmVarDecl(hasName("p3")))))))); + EXPECT_TRUE(notMatches(Fragment, unresolvedLookupExpr(hasAnyDeclaration( + functionDecl(hasName("bar")))))); +} + } // namespace ast_matchers } // namespace clang |