Author: max-winkler
Date: 2026-10-17T10:00:31+08:00
New Revision: 5a9da12223bd112ae249eb11c34d48be3b3f55cc

URL: 
https://github.com/llvm/llvm-project/commit/5a9da12223bd112ae249eb11c34d48be3b3f55cc
DIFF: 
https://github.com/llvm/llvm-project/commit/5a9da12223bd112ae249eb11c34d48be3b3f55cc.diff

LOG: [clang] Fix incorrect PackIndexingTypeLoc traversal in RecursiveASTVisitor 
(#231191)

Fixes [clangd/clangd#2713](https://github.com/clangd/clangd/issues/2713)

Assisted-by: Claude

Added: 
    

Modified: 
    clang-tools-extra/clangd/unittests/FindTargetTests.cpp
    clang/include/clang/AST/RecursiveASTVisitor.h
    clang/unittests/AST/SourceLocationTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp 
b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index cd57eb7d912b8..388dfe7a0e7aa 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -691,6 +691,15 @@ TEST_F(TargetDeclTest, PackIndexing) {
   )cpp";
   EXPECT_DECLS("TemplateSpecializationTypeLoc",
                "template <typename> class ...X");
+
+  Code = R"cpp(
+    // Indexed type template parameter pack
+    template <typename... X>
+    void foo() {
+      [[X]]...[0] x;
+    }
+  )cpp";
+  EXPECT_DECLS("TemplateTypeParmTypeLoc", "typename ...X");
 }
 
 TEST_F(TargetDeclTest, PackIndexedConcept) {

diff  --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index f144c890f6ee6..13dd5eda84fa6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1469,7 +1469,7 @@ DEF_TRAVERSE_TYPELOC(DecltypeType, {
 })
 
 DEF_TRAVERSE_TYPELOC(PackIndexingType, {
-  TRY_TO(TraverseType(TL.getPattern()));
+  TRY_TO(TraverseTypeLoc(TL.getPatternLoc()));
   TRY_TO(TraverseStmt(TL.getTypePtr()->getIndexExpr()));
 })
 

diff  --git a/clang/unittests/AST/SourceLocationTest.cpp 
b/clang/unittests/AST/SourceLocationTest.cpp
index 06993a0270300..4cc3c7aae9829 100644
--- a/clang/unittests/AST/SourceLocationTest.cpp
+++ b/clang/unittests/AST/SourceLocationTest.cpp
@@ -1111,6 +1111,26 @@ TEST(PackIndexingTypeLoc, PatternAndEllipsisLoc) {
       typeLoc(hasParent(varDecl(hasName("x")))), Lang_CXX26));
 }
 
+TEST(PackIndexingTypeLoc, PatternIsTraversed) {
+  RangeVerifier<TypeLoc> Verifier;
+  Verifier.expectRange(2, 8, 2, 8);
+  EXPECT_TRUE(Verifier.match(
+      R"cpp(template <class... T> void foo() {
+       T...[0] x;
+  })cpp",
+      typeLoc(loc(templateTypeParmType())), Lang_CXX26));
+}
+
+TEST(PackIndexingTypeLoc, PatternIsTraversedInAlias) {
+  RangeVerifier<TypeLoc> Verifier;
+  Verifier.expectRange(2, 18, 2, 18);
+  EXPECT_TRUE(Verifier.match(
+      R"cpp(template <class... T> void foo() {
+       using U = T...[0];
+  })cpp",
+      typeLoc(loc(templateTypeParmType())), Lang_CXX26));
+}
+
 class ConceptSpecializationExprConceptReferenceRangeVerifier
     : public RangeVerifier<VarTemplateDecl> {
 protected:


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to