https://github.com/mizvekov created https://github.com/llvm/llvm-project/pull/189559
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 >From 538ce9e6f7aa4cbdb4a8e8389827810a97b286c0 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <[email protected]> Date: Sat, 28 Mar 2026 23:54:18 +0000 Subject: [PATCH] [clang] fix getReplacedTemplateParameter for function template specializaions 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 --- clang/lib/AST/DeclTemplate.cpp | 10 ++++++---- clang/test/SemaTemplate/GH188759.cpp | 13 +++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 clang/test/SemaTemplate/GH188759.cpp 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@-1 {{use of undeclared identifier 'operator0'}} + }(integer_sequence<1>{}); + } + template void runBlobs<2, {}>(); // expected-note {{requested here}} +} // namespace t1 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
