Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/docs/LibASTMatchersReference.html
Original file line number Diff line number Diff line change
Expand Up @@ -4683,8 +4683,10 @@ <h2 id="narrowing-matchers">Narrowing Matchers</h2>
static int i = 0;
extern int j;
int k;
static void l();
void l() {}
functionDecl(isStaticStorageClass())
matches the function declaration f.
matches the function declaration of f and l, and the definition of l.
varDecl(isStaticStorageClass())
matches the variable declaration i.
</pre></td></tr>
Expand Down
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,9 @@ AST Matchers

- Ensure ``pointee`` matches Objective-C pointer types.

- Fixed `isStaticStorageClass` not matching the definition if the definition was
not marked `static` as well.

clang-format
------------

Expand Down
6 changes: 4 additions & 2 deletions clang/include/clang/ASTMatchers/ASTMatchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -5418,15 +5418,17 @@ AST_POLYMORPHIC_MATCHER(isExternC, AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
/// static int i = 0;
/// extern int j;
/// int k;
/// static void l();
/// void l() {}
/// \endcode
/// functionDecl(isStaticStorageClass())
/// matches the function declaration f.
/// matches the function declaration of f and l, and the definition of l.
/// varDecl(isStaticStorageClass())
/// matches the variable declaration i.
AST_POLYMORPHIC_MATCHER(isStaticStorageClass,
AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
VarDecl)) {
return Node.getStorageClass() == SC_Static;
return Node.getCanonicalDecl()->getStorageClass() == SC_Static;
}

/// Matches deleted function declarations.
Expand Down
8 changes: 8 additions & 0 deletions clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1826,6 +1826,14 @@ TEST_P(ASTMatchersTest, IsStaticStorageClass) {
EXPECT_TRUE(notMatches("int i = 1;", varDecl(isStaticStorageClass())));
EXPECT_TRUE(notMatches("extern int i;", varDecl(isStaticStorageClass())));
EXPECT_TRUE(notMatches("void f() {}", functionDecl(isStaticStorageClass())));

if (!GetParam().isCXX())
return;

EXPECT_TRUE(matches("static void foo(); void foo() {}",
functionDecl(isDefinition(), isStaticStorageClass())));
Comment on lines +1833 to +1834
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static function also available in C.

EXPECT_TRUE(matches("struct A { static void bar(); }; void A::bar() {}",
cxxMethodDecl(isDefinition(), isStaticStorageClass())));
}

TEST_P(ASTMatchersTest, IsDefaulted) {
Expand Down
Loading