Index: cfe/trunk/docs/LibASTMatchersReference.html =================================================================== --- cfe/trunk/docs/LibASTMatchersReference.html +++ cfe/trunk/docs/LibASTMatchersReference.html @@ -2610,6 +2610,20 @@ +
Matches variablefunction declarations that have static storage class +(with "static" key word) written in the source. + +Given: + static void f() {} + static int i = 0; +functionDecl(isStaticStorageClass()) + matches the function declaration f. +varDecl(isStaticStorageClass()) + matches the variable declaration i. +
Matches template instantiations of function, class, or static member variable template instantiations. @@ -3473,6 +3487,20 @@
Matches variablefunction declarations that have static storage class +(with "static" key word) written in the source. + +Given: + static void f() {} + static int i = 0; +functionDecl(isStaticStorageClass()) + matches the function declaration f. +varDecl(isStaticStorageClass()) + matches the variable declaration i. +
Matches template instantiations of function, class, or static member variable template instantiations. @@ -4092,7 +4120,7 @@- Matcher<CXXMethodDecl> forEachOverridden Matcher<CXXMethodDecl> InnerMatcher Matches each method overridden by the given method. This matcher may + Matches each method overriden by the given method. This matcher may produce multiple matches. Given Index: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h =================================================================== --- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h +++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h @@ -3387,6 +3387,24 @@ return Node.isExternC(); } +/// \brief Matches variable/function declarations that have static storage class +/// (with "static" key word) written in the source. +/// +/// Given: +/// \code +/// static void f() {} +/// static int i = 0; +/// \endcode +/// functionDecl(isStaticStorageClass()) +/// matches the function declaration f. +/// varDecl(isStaticStorageClass()) +/// matches the variable declaration i. +AST_POLYMORPHIC_MATCHER(isStaticStorageClass, + AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl, + VarDecl)) { + return Node.getStorageClass() == SC_Static; +} + /// \brief Matches deleted function declarations. /// /// Given: Index: cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp =================================================================== --- cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp +++ cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp @@ -848,6 +848,14 @@ EXPECT_TRUE(notMatches("int i;", varDecl(isExternC()))); } +TEST(IsStaticStorageClass, MatchesStaticDeclarations) { + EXPECT_TRUE( + matches("static void f() {}", functionDecl(isStaticStorageClass()))); + EXPECT_TRUE(matches("static int i = 1;", varDecl(isStaticStorageClass()))); + EXPECT_TRUE(notMatches("int i = 1;", varDecl(isStaticStorageClass()))); + EXPECT_TRUE(notMatches("void f() {}", functionDecl(isStaticStorageClass()))); +} + TEST(IsDefaulted, MatchesDefaultedFunctionDeclarations) { EXPECT_TRUE(notMatches("class A { ~A(); };", functionDecl(hasName("~A"), isDefaulted())));