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 | 8cef2c2f2dd94e9e8aa84f254bf3efdbf216cd03 (patch) | |
| tree | a15c2166f97d27f3b63ef28400ff08a18d882c8f /clang/unittests | |
| parent | c710a461b57e0540a97b123691d8dbac443d2a17 (diff) | |
| download | bcm5719-llvm-8cef2c2f2dd94e9e8aa84f254bf3efdbf216cd03.tar.gz bcm5719-llvm-8cef2c2f2dd94e9e8aa84f254bf3efdbf216cd03.zip | |
[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
llvm-svn: 278123
Diffstat (limited to 'clang/unittests')
| -rw-r--r-- | clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp index 41d588f122b..fcd3dcb5af0 100644 --- a/clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp +++ b/clang/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 |

