[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

llvm-svn: 213152

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

index ce32039..1ff4ab3 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 f5cb130..bd7a5a6 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()))));