Index: docs/LibASTMatchersReference.html =================================================================== --- docs/LibASTMatchersReference.html +++ docs/LibASTMatchersReference.html @@ -3493,6 +3493,17 @@ +
Matches a variable declaration that is a static data member.
+
+Example matches x (matcher = varDecl(isStaticDataMember())
+class A {
+ static int x;
+ int y;
+};
+Matches variablefunction declarations that have "static" storage
class specifier ("static" keyword) written in the source.
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2993,6 +2993,19 @@
return Node.isExceptionVariable();
}
+/// \brief Matches a variable declaration that is a static data member.
+///
+/// Example matches x (matcher = varDecl(isStaticDataMember())
+/// \code
+/// class A {
+/// static int x;
+/// int y;
+/// };
+/// \endcode
+AST_MATCHER(VarDecl, isStaticDataMember) {
+ return Node.isStaticDataMember();
+}
+
/// \brief Checks that a call expression or a constructor call expression has
/// a specific number of arguments (including absent default arguments).
///
Index: unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -692,6 +692,15 @@
EXPECT_TRUE(notMatches(T, varDecl(hasName("a"), hasThreadStorageDuration())));
}
+TEST(Matcher, VarDecl_StaticDataMember) {
+ EXPECT_TRUE(matches(
+ "class A {static int x; int y;};",
+ varDecl(hasName("x"), isStaticDataMember())));
+ EXPECT_TRUE(notMatches(
+ "class A {int x;};",
+ varDecl(isStaticDataMember())));
+}
+
TEST(Matcher, FindsVarDeclInFunctionParameter) {
EXPECT_TRUE(matches(
"void f(int i) {}",