diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html --- a/clang/docs/LibASTMatchersReference.html +++ b/clang/docs/LibASTMatchersReference.html @@ -4310,15 +4310,17 @@
Matches function and namespace declarations that are marked with +@@ -4689,11 +4691,13 @@ the inline keyword. Given + inline constexpr int i = 1; inline void f(); void g(); namespace n { inline namespace m {} } +varDecl(isInline()) will match ::i. functionDecl(isInline()) will match ::f(). namespaceDecl(isInline()) will match n::m. Matches variable, function and namespace declarations that are marked with the inline keyword. Given + inline constexpr int i = 1; inline void f(); void g(); namespace n { inline namespace m {} } +varDecl(isInline()) will match ::i. functionDecl(isInline()) will match ::f(). namespaceDecl(isInline()) will match n::m.
Matches variable, function and namespace declarations that are marked with
+the inline keyword.
+
+Given
+ inline constexpr int i = 1;
+ inline void f();
+ void g();
+ namespace n {
+ inline namespace m {}
+ }
+varDecl(isInline()) will match ::i.
+functionDecl(isInline()) will match ::f().
+namespaceDecl(isInline()) will match n::m.
+Matches a static variable with local scope.
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,8 @@
AST Matchers
------------
+- The ``isInline`` matcher now accepts inline variable declarations.
+
clang-format
------------
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -7673,25 +7673,29 @@
return InnerMatcher.matches(*ES.getExpr(), Finder, Builder);
}
-/// Matches function and namespace declarations that are marked with
+/// Matches variable, function and namespace declarations that are marked with
/// the inline keyword.
///
/// Given
/// \code
+/// inline constexpr int i = 1;
/// inline void f();
/// void g();
/// namespace n {
/// inline namespace m {}
/// }
/// \endcode
+/// varDecl(isInline()) will match ::i.
/// functionDecl(isInline()) will match ::f().
/// namespaceDecl(isInline()) will match n::m.
AST_POLYMORPHIC_MATCHER(isInline,
- AST_POLYMORPHIC_SUPPORTED_TYPES(NamespaceDecl,
- FunctionDecl)) {
+ AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl, FunctionDecl,
+ NamespaceDecl)) {
// This is required because the spelling of the function used to determine
// whether inline is specified or not differs between the polymorphic types.
- if (const auto *FD = dyn_cast(&Node))
+ if (const auto *VD = dyn_cast(&Node))
+ return VD->isInline();
+ else if (const auto *FD = dyn_cast(&Node))
return FD->isInlineSpecified();
else if (const auto *NSD = dyn_cast(&Node))
return NSD->isInline();
diff --git a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
--- a/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersInternalTest.cpp
@@ -192,13 +192,6 @@
llvm::ValueIs(TK_IgnoreUnlessSpelledInSource));
}
-TEST(IsInlineMatcher, IsInline) {
- EXPECT_TRUE(matches("void g(); inline void f();",
- functionDecl(isInline(), hasName("f"))));
- EXPECT_TRUE(matches("namespace n { inline namespace m {} }",
- namespaceDecl(isInline(), hasName("m"))));
-}
-
// FIXME: Figure out how to specify paths so the following tests pass on
// Windows.
#ifndef _WIN32
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -1455,6 +1455,23 @@
"int main() { int x = 3; auto f = [vd=x]() { return vd; }; }", M));
}
+TEST_P(ASTMatchersTest, IsInline) {
+ if (!GetParam().isCXX() && !GetParam().isC99OrLater())
+ return;
+ EXPECT_TRUE(matches("void g(); inline void f();",
+ functionDecl(isInline(), hasName("f"))));
+
+ if (!GetParam().isCXX())
+ return;
+ EXPECT_TRUE(matches("namespace n { inline namespace m {} }",
+ namespaceDecl(isInline(), hasName("m"))));
+
+ if (!GetParam().isCXX17OrLater())
+ return;
+ EXPECT_TRUE(matches("inline constexpr int i = 1;",
+ varDecl(isInline(), hasName("i"))));
+}
+
TEST_P(ASTMatchersTest, StorageDuration) {
StringRef T =
"void f() { int x; static int y; } int a;static int b;extern int c;";