https://github.com/HighCommander4 created https://github.com/llvm/llvm-project/pull/228996
The code was already handling template template parameters, but it used TemplateName::getAsTemplateDecl() which does not work for a template template parameter referenced inside a pack index. Fixes https://github.com/clangd/clangd/issues/2712 >From 7fa240107cacdfac94cb15704955817c8005573a Mon Sep 17 00:00:00 2001 From: Nathan Ridge <[email protected]> Date: Sat, 3 Oct 2026 20:58:20 -0400 Subject: [PATCH] [clangd] Handle template template parameter pack indexes correctly in TargetFinder::VisitTemplateSpecializationType The code was already handling template template parameters, but it used TemplateName::getAsTemplateDecl() which does not work for a template template parameter referenced inside a pack index. Fixes https://github.com/clangd/clangd/issues/2712 --- clang-tools-extra/clangd/FindTarget.cpp | 3 +-- clang-tools-extra/clangd/unittests/FindTargetTests.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp index a3379d1337d62ea..efdb24086a27fcb 100644 --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -454,8 +454,7 @@ struct TargetFinder { // specializations of template template parameters aren't instantiated // into decls, so they must refer to the parameter itself. else if (const auto *Parm = - llvm::dyn_cast_or_null<TemplateTemplateParmDecl>( - TST->getTemplateName().getAsTemplateDecl())) + TST->getTemplateName().getAsTemplateTemplateParmDecl()) Outer.add(Parm, Flags); // class template specializations have a (specialized) CXXRecordDecl. else if (const CXXRecordDecl *RD = TST->getAsCXXRecordDecl()) diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp index 94837803cd64c71..8eb70597a5713d8 100644 --- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -626,6 +626,16 @@ TEST_F(TargetDeclTest, ClassTemplate) { )cpp"; EXPECT_DECLS("DeducedTemplateSpecializationTypeLoc", "template <typename> class ...X"); + + Code = R"cpp( + // Specialization of an indexed template template parameter pack + template <template <typename> class... X> + void foo() { + [[X]]...[0]<int> x; + } + )cpp"; + EXPECT_DECLS("TemplateSpecializationTypeLoc", + "template <typename> class ...X"); } TEST_F(TargetDeclTest, Concept) { _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
