From: Benjamin Kramer Date: Wed, 16 Jul 2014 14:14:51 +0000 (+0000) Subject: [ASTMatchers] Add a usingDirectiveDecl matcher. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2d3dce1b036e2114b50c328b4cecbb7c8493a2c1;p=clang [ASTMatchers] Add a usingDirectiveDecl matcher. This matches 'using namespace' declarations. Differential Revision: http://reviews.llvm.org/D4517 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213152 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h index ce32039c14..1ff4ab367f 100644 --- a/include/clang/ASTMatchers/ASTMatchers.h +++ b/include/clang/ASTMatchers/ASTMatchers.h @@ -714,6 +714,18 @@ substNonTypeTemplateParmExpr; /// matches \code using X::x \endcode const internal::VariadicDynCastAllOfMatcher usingDecl; +/// \brief Matches using namespace declarations. +/// +/// Given +/// \code +/// namespace X { int x; } +/// using namespace X; +/// \endcode +/// usingDirectiveDecl() +/// matches \code using namespace X \endcode +const internal::VariadicDynCastAllOfMatcher + usingDirectiveDecl; + /// \brief Matches unresolved using value declarations. /// /// Given diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp index f5cb130b1d..bd7a5a6df8 100644 --- a/unittests/ASTMatchers/ASTMatchersTest.cpp +++ b/unittests/ASTMatchers/ASTMatchersTest.cpp @@ -3038,6 +3038,13 @@ TEST(UsingDeclaration, ThroughUsingDeclaration) { declRefExpr(throughUsingDecl(anything())))); } +TEST(UsingDirectiveDeclaration, MatchesUsingNamespace) { + EXPECT_TRUE(matches("namespace X { int x; } using namespace X;", + usingDirectiveDecl())); + EXPECT_FALSE( + matches("namespace X { int x; } using X::x;", usingDirectiveDecl())); +} + TEST(SingleDecl, IsSingleDecl) { StatementMatcher SingleDeclStmt = declStmt(hasSingleDecl(varDecl(hasInitializer(anything()))));