[clang] [clang][Sema] Handle function parameter packs in `getDepthAndIndex(UnexpandedParameterPack)` (PR #215235)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 10 06:27:29 PDT 2026
https://github.com/zwuis updated https://github.com/llvm/llvm-project/pull/215235
>From 2fb93a84edce0012e09c4c633c091f25b96001b0 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu <zwuis at outlook.com>
Date: Mon, 10 Aug 2026 18:15:58 +0800
Subject: [PATCH 1/2] Handle function parameter packs in
`getDepthAndIndex(UnexpandedParameterPack)`
---
clang/docs/ReleaseNotes.md | 2 ++
clang/include/clang/Sema/SemaInternal.h | 12 +++++++-----
clang/test/SemaTemplate/deduction-crash.cpp | 16 ++++++++++++++++
3 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index fc947d05fad83..75a5afd7a2648 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -445,6 +445,8 @@ features cannot lower the translation-unit ABI level;
affect C++26 constexpr structured bindings and expansion statements, but
also affects some uses of plain structured bindings. (#GH211930)
+- Fixed a crash during template argument deduction where a function parameter pack is referenced by other types in the function type. (GH28877, GH213760)
+
#### Bug Fixes to AST Handling
- Fixed a non-deterministic ordering of unused local typedefs that made
diff --git a/clang/include/clang/Sema/SemaInternal.h b/clang/include/clang/Sema/SemaInternal.h
index 8f6041b5f00e4..58b9ec537b4bd 100644
--- a/clang/include/clang/Sema/SemaInternal.h
+++ b/clang/include/clang/Sema/SemaInternal.h
@@ -77,11 +77,13 @@ inline std::optional<std::pair<unsigned, unsigned>>
getDepthAndIndex(UnexpandedParameterPack UPP) {
if (const auto *TTP = dyn_cast<const TemplateTypeParmType *>(UPP.first))
return std::make_pair(TTP->getDepth(), TTP->getIndex());
- if (isa<NamedDecl *>(UPP.first))
- return getDepthAndIndex(cast<NamedDecl *>(UPP.first));
- assert((isa<const TemplateSpecializationType *,
- const SubstBuiltinTemplatePackType *>(UPP.first)));
- return std::nullopt;
+ if (isa<const TemplateSpecializationType *,
+ const SubstBuiltinTemplatePackType *>(UPP.first))
+ return std::nullopt;
+ const auto *ND = cast<NamedDecl *>(UPP.first);
+ if (isa<ParmVarDecl>(ND))
+ return std::nullopt;
+ return getDepthAndIndex(ND);
}
class TypoCorrectionConsumer : public VisibleDeclConsumer {
diff --git a/clang/test/SemaTemplate/deduction-crash.cpp b/clang/test/SemaTemplate/deduction-crash.cpp
index e7018fd0d8338..2b0befb34a2df 100644
--- a/clang/test/SemaTemplate/deduction-crash.cpp
+++ b/clang/test/SemaTemplate/deduction-crash.cpp
@@ -177,3 +177,19 @@ namespace GH177545 {
template<decltype(auto)()() volatile throw() -> char> // expected-error {{'decltype(auto)' can only be used as a return type in a function declaration}}
struct T2; // expected-error@* {{function cannot return function type 'auto () volatile throw() -> decltype(auto)'}}
}
+
+namespace GH28877 {
+template <typename...> struct S;
+template <typename... Ts> auto f(Ts... args) -> S<decltype(args)...>;
+extern template auto f() -> S<>;
+}
+
+namespace GH46548 {
+template <typename... Ts> void a(Ts... args1, char... args2[][sizeof args1]);
+extern template void a();
+}
+
+namespace GH213760 {
+template <typename... Ts> void f(Ts... args, decltype(args)...);
+void g() { f(); }
+}
>From 698c3f6f4c553a49d1cc52d6f1a046cc2da32d08 Mon Sep 17 00:00:00 2001
From: Yanzuo Liu <zwuis at outlook.com>
Date: Mon, 10 Aug 2026 21:27:18 +0800
Subject: [PATCH 2/2] Update ReleaseNotes.md
---
clang/docs/ReleaseNotes.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 75a5afd7a2648..5df4bce981b10 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -445,7 +445,7 @@ features cannot lower the translation-unit ABI level;
affect C++26 constexpr structured bindings and expansion statements, but
also affects some uses of plain structured bindings. (#GH211930)
-- Fixed a crash during template argument deduction where a function parameter pack is referenced by other types in the function type. (GH28877, GH213760)
+- Fixed an assertion during template argument deduction where a function parameter pack is referenced by other types in the function type. (GH28877, GH213760)
#### Bug Fixes to AST Handling
More information about the cfe-commits
mailing list