[clang] Handle variable templates in `isInstantiated` and `isInTemplateInstantiation` matchers (PR #110666)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 1 06:29:44 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff b8b036a7fe5b6e7ec306e3b80367e22d157a492b d30b8c9893479482eec7e1cd43bf8ebc5196d042 --extensions cpp,h -- clang/include/clang/ASTMatchers/ASTMatchers.h clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index 2ba3542ec1..1b8757f422 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -6770,10 +6770,9 @@ AST_MATCHER_FUNCTION(internal::Matcher<Decl>, isInstantiated) {
/// will NOT match j += 42; as it's shared between the template definition and
/// instantiation.
AST_MATCHER_FUNCTION(internal::Matcher<Stmt>, isInTemplateInstantiation) {
- return stmt(
- hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
- functionDecl(isTemplateInstantiation()),
- varDecl(isTemplateInstantiation())))));
+ return stmt(hasAncestor(decl(anyOf(cxxRecordDecl(isTemplateInstantiation()),
+ functionDecl(isTemplateInstantiation()),
+ varDecl(isTemplateInstantiation())))));
}
/// Matches explicit template specializations of function, class, or
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
index 6147dbd37d..65904a1891 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
@@ -3313,15 +3313,13 @@ TEST_P(ASTMatchersTest,
declStmt(isInTemplateInstantiation())));
}
-
TEST_P(ASTMatchersTest, IsInstantiated_MatchesVariableInstantiation) {
if (!GetParam().isCXX14OrLater()) {
return;
}
- EXPECT_TRUE(
- matches("template<typename T> int V = 10; void x() { V<int>; }",
- varDecl(isInstantiated())));
+ EXPECT_TRUE(matches("template<typename T> int V = 10; void x() { V<int>; }",
+ varDecl(isInstantiated())));
}
TEST_P(ASTMatchersTest, IsInstantiated_NotMatchesVariableDefinition) {
@@ -3339,9 +3337,9 @@ TEST_P(ASTMatchersTest,
return;
}
- EXPECT_TRUE(
- matches("template<typename T> auto V = []() { T i; }; void x() { V<int>(); }",
- declStmt(isInTemplateInstantiation())));
+ EXPECT_TRUE(matches(
+ "template<typename T> auto V = []() { T i; }; void x() { V<int>(); }",
+ declStmt(isInTemplateInstantiation())));
}
TEST_P(ASTMatchersTest,
``````````
</details>
https://github.com/llvm/llvm-project/pull/110666
More information about the cfe-commits
mailing list