From: Benjamin Kramer Date: Thu, 4 Aug 2016 10:02:03 +0000 (+0000) Subject: Make isExternC work on VarDecls too. X-Git-Tag: llvmorg-4.0.0-rc1~13344 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=87e6d99487ddd7ba4bdc582600f0dfc2ef271ae7;p=platform%2Fupstream%2Fllvm.git Make isExternC work on VarDecls too. llvm-svn: 277712 --- diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html index 35534cb..02af5d5 100644 --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -3441,6 +3441,18 @@ Usable as: Matcher<VarDecl>isExternC +
Matches extern "C" function declarations.
+
+Given:
+  extern "C" void f() {}
+  extern "C" { void g() {} }
+  void h() {}
+functionDecl(isExternC())
+  matches the declaration of f and g, but not the declaration h
+
+ + Matcher<VarDecl>isTemplateInstantiation
Matches template instantiations of function, class, or static
 member variable template instantiations.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index eee713c..2a5f047 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -3342,7 +3342,8 @@ AST_MATCHER_P(FunctionDecl, returns,
 /// \endcode
 /// functionDecl(isExternC())
 ///   matches the declaration of f and g, but not the declaration h
-AST_MATCHER(FunctionDecl, isExternC) {
+AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+                                                                   VarDecl)) {
   return Node.isExternC();
 }
 
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 82c5139..108fd43 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -842,6 +842,12 @@ TEST(IsExternC, MatchesExternCFunctionDeclarations) {
   EXPECT_TRUE(notMatches("void f() {}", functionDecl(isExternC())));
 }
 
+TEST(IsExternC, MatchesExternCVariableDeclarations) {
+  EXPECT_TRUE(matches("extern \"C\" int i;", varDecl(isExternC())));
+  EXPECT_TRUE(matches("extern \"C\" { int i; }", varDecl(isExternC())));
+  EXPECT_TRUE(notMatches("int i;", varDecl(isExternC())));
+}
+
 TEST(IsDefaulted, MatchesDefaultedFunctionDeclarations) {
   EXPECT_TRUE(notMatches("class A { ~A(); };",
                          functionDecl(hasName("~A"), isDefaulted())));