Skip to content

release/22.x: [clang] fix getReplacedTemplateParameter for function template specializations (#189559)#189596

Open
llvmbot wants to merge 1 commit intollvm:release/22.xfrom
llvmbot:issue189559
Open

release/22.x: [clang] fix getReplacedTemplateParameter for function template specializations (#189559)#189596
llvmbot wants to merge 1 commit intollvm:release/22.xfrom
llvmbot:issue189559

Conversation

@llvmbot
Copy link
Copy Markdown
Member

@llvmbot llvmbot commented Mar 31, 2026

Backport 2b43932

Requested by: @zyn0217

@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Mar 31, 2026

@zyn0217 What do you think about merging this PR to the release branch?

@llvmbot llvmbot requested a review from zyn0217 March 31, 2026 11:02
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Mar 31, 2026
@llvmbot
Copy link
Copy Markdown
Member Author

llvmbot commented Mar 31, 2026

@llvm/pr-subscribers-clang

Author: llvmbot

Changes

Backport 2b43932

Requested by: @zyn0217


Full diff: https://github.com/llvm/llvm-project/pull/189596.diff

2 Files Affected:

  • (modified) clang/lib/AST/DeclTemplate.cpp (+6-4)
  • (added) clang/test/SemaTemplate/GH188759.cpp (+13)
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index ed20c720ce06c..4e77a2c4686eb 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -1713,10 +1713,12 @@ clang::getReplacedTemplateParameter(Decl *D, unsigned Index) {
   case Decl::Kind::CXXConstructor:
   case Decl::Kind::CXXDestructor:
   case Decl::Kind::CXXMethod:
-  case Decl::Kind::Function:
-    return getReplacedTemplateParameter(
-        cast<FunctionDecl>(D)->getTemplateSpecializationInfo()->getTemplate(),
-        Index);
+  case Decl::Kind::Function: {
+    const FunctionTemplateSpecializationInfo *Info =
+        cast<FunctionDecl>(D)->getTemplateSpecializationInfo();
+    return {Info->getTemplate()->getTemplateParameters()->getParam(Index),
+            Info->TemplateArguments->asArray()[Index]};
+  }
   default:
     llvm_unreachable("Unhandled templated declaration kind");
   }
diff --git a/clang/test/SemaTemplate/GH188759.cpp b/clang/test/SemaTemplate/GH188759.cpp
new file mode 100644
index 0000000000000..f0d579d1fc3e5
--- /dev/null
+++ b/clang/test/SemaTemplate/GH188759.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++26 %s
+
+namespace t1 {
+  template <int> struct integer_sequence {};
+  template <int> struct array {};
+  template <int ARRAY_SIZE, array<ARRAY_SIZE> test_apdus> void runBlobs() {
+    []<int... INDEX>(integer_sequence<INDEX...>) { // expected-note {{requested here}}
+      int x{operator0<test_apdus, INDEX>()...};
+      // expected-error@-1 {{use of undeclared identifier 'operator0'}}
+    }(integer_sequence<1>{});
+  }
+  template void runBlobs<2, {}>(); // expected-note {{requested here}}
+} // namespace t1

@zyn0217 zyn0217 requested review from cor3ntin and erichkeane March 31, 2026 11:03
@c-rhodes c-rhodes moved this from Needs Triage to Needs Review in LLVM Release Status Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

3 participants