From 057305f6857a64c487a07750a14f2892695ea76a Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Thu, 4 Sep 2014 08:51:06 +0000 Subject: [PATCH] Add matcher for linkage specification Patch by Jacques Pienaar. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@217135 91177308-0d34-0410-b5e6-96231b3b80d8 --- docs/LibASTMatchersReference.html | 10 ++++++++++ include/clang/ASTMatchers/ASTMatchers.h | 11 +++++++++++ unittests/ASTMatchers/ASTMatchersTest.cpp | 5 +++++ 3 files changed, 26 insertions(+) diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index 1a494e6aea..2c2b68de93 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -246,6 +246,16 @@ Example matches f +Matcher<Decl>linkageSpecDeclMatcher<LinkageSpecDecl>... +
Matches a declaration of a linkage specification.
+
+Given
+  extern "C" {}
+linkageSpecDecl()
+  matches "extern "C" {}"
+
+ + Matcher<Decl>methodDeclMatcher<CXXMethodDecl>...
Matches method declarations.
 
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index b010dd5936..23edcc6756 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -156,6 +156,17 @@ anything() {
 /// \endcode
 const internal::VariadicAllOfMatcher decl;
 
+/// \brief Matches a declaration of a linkage specification.
+///
+/// Given
+/// \code
+///   extern "C" {}
+/// \endcode
+/// linkageSpecDecl()
+///   matches "extern "C" {}"
+const internal::VariadicDynCastAllOfMatcher
+    linkageSpecDecl;
+
 /// \brief Matches a declaration of anything that could have a name.
 ///
 /// Example matches \c X, \c S, the anonymous union type, \c i, and \c U;
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 3fbe896a87..e074c6ecc0 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -377,6 +377,11 @@ TEST(DeclarationMatcher, hasDeclContext) {
                           hasName("M"), hasDeclContext(namespaceDecl()))))));
 }
 
+TEST(DeclarationMatcher, LinkageSpecification) {
+  EXPECT_TRUE(matches("extern \"C\" { void foo() {}; }", linkageSpecDecl()));
+  EXPECT_TRUE(notMatches("void foo() {};", linkageSpecDecl()));
+}
+
 TEST(ClassTemplate, DoesNotMatchClass) {
   DeclarationMatcher ClassX = classTemplateDecl(hasName("X"));
   EXPECT_TRUE(notMatches("class X;", ClassX));
-- 
2.40.0