]> granicus.if.org Git - clang/commitdiff
[ASTMatchers] Add a usingDirectiveDecl matcher.
authorBenjamin Kramer <benny.kra@googlemail.com>
Wed, 16 Jul 2014 14:14:51 +0000 (14:14 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Wed, 16 Jul 2014 14:14:51 +0000 (14:14 +0000)
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

include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp

index ce32039c14afc7dd87214fcb1041be2a79f1685e..1ff4ab367fd58401d246e21cb60eefe486562b6e 100644 (file)
@@ -714,6 +714,18 @@ substNonTypeTemplateParmExpr;
 ///   matches \code using X::x \endcode
 const internal::VariadicDynCastAllOfMatcher<Decl, UsingDecl> 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<Decl, UsingDirectiveDecl>
+    usingDirectiveDecl;
+
 /// \brief Matches unresolved using value declarations.
 ///
 /// Given
index f5cb130b1d7344ead670d6c76baf56a96a2baff4..bd7a5a6df8f36ddb7f7eac545fe475166835e5b6 100644 (file)
@@ -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()))));