aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/ASTMatchers/ASTMatchers.h14
-rw-r--r--unittests/ASTMatchers/ASTMatchersTest.cpp12
2 files changed, 23 insertions, 3 deletions
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index f10addcb7a..fdb8709ec2 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -129,7 +129,8 @@ typedef internal::Matcher<NestedNameSpecifierLoc> NestedNameSpecifierLocMatcher;
/// \endcode
///
/// Usable as: Any Matcher
-inline internal::PolymorphicMatcherWithParam0<internal::TrueMatcher> anything() {
+inline internal::PolymorphicMatcherWithParam0<internal::TrueMatcher>
+anything() {
return internal::PolymorphicMatcherWithParam0<internal::TrueMatcher>();
}
@@ -157,6 +158,17 @@ const internal::VariadicAllOfMatcher<Decl> decl;
/// \endcode
const internal::VariadicDynCastAllOfMatcher<Decl, NamedDecl> namedDecl;
+/// \brief Matches a declaration of a namespace.
+///
+/// Given
+/// \code
+/// namespace {}
+/// namespace test {}
+/// \endcode
+/// namespaceDecl()
+/// matches "namespace {}" and "namespace test {}"
+const internal::VariadicDynCastAllOfMatcher<Decl, NamespaceDecl> namespaceDecl;
+
/// \brief Matches C++ class declarations.
///
/// Example matches \c X, \c Z
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 301b4f7c8a..82f349fb0e 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -337,14 +337,22 @@ TEST(DeclarationMatcher, hasDeclContext) {
" class D {};"
" }"
"}",
- recordDecl(hasDeclContext(namedDecl(hasName("M"))))));
+ recordDecl(hasDeclContext(namespaceDecl(hasName("M"))))));
EXPECT_TRUE(notMatches(
"namespace N {"
" namespace M {"
" class D {};"
" }"
"}",
- recordDecl(hasDeclContext(namedDecl(hasName("N"))))));
+ recordDecl(hasDeclContext(namespaceDecl(hasName("N"))))));
+
+ EXPECT_TRUE(matches("namespace {"
+ " namespace M {"
+ " class D {};"
+ " }"
+ "}",
+ recordDecl(hasDeclContext(namespaceDecl(
+ hasName("M"), hasDeclContext(namespaceDecl()))))));
}
TEST(ClassTemplate, DoesNotMatchClass) {