[clang] [clang] fix getReplacedTemplateParameter for function template specializations (PR #189559)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 01:20:11 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
This fixes the transformation of substituted constant template parameters by providing the instantiated parameter type for the function template specialization case.
This fixes a regression introduced in #<!-- -->161029 which will be backported to llvm-22, so there are no release notes.
Fixes #<!-- -->188759
---
Full diff: https://github.com/llvm/llvm-project/pull/189559.diff
2 Files Affected:
- (modified) clang/lib/AST/DeclTemplate.cpp (+6-4)
- (added) clang/test/SemaTemplate/GH188759.cpp (+13)
``````````diff
diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index 5a8e1ed445f3a..99d02fdc99e92 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -1707,10 +1707,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 at -1 {{use of undeclared identifier 'operator0'}}
+ }(integer_sequence<1>{});
+ }
+ template void runBlobs<2, {}>(); // expected-note {{requested here}}
+} // namespace t1
``````````
</details>
https://github.com/llvm/llvm-project/pull/189559
More information about the cfe-commits
mailing list