Author: Yanzuo Liu
Date: 2026-08-20T11:47:22Z
New Revision: 1ae007f6e9a864425b37187b1ae4c041a198461e

URL: 
https://github.com/llvm/llvm-project/commit/1ae007f6e9a864425b37187b1ae4c041a198461e
DIFF: 
https://github.com/llvm/llvm-project/commit/1ae007f6e9a864425b37187b1ae4c041a198461e.diff

LOG: [clang][Sema] Handle function parameter packs in 
`PackDeductionScope::addPacks` (#215235)

`getDepthAndIndex` assumes its parameter never refers to a function
parameter pack. Bail out before calling it for function parameter packs.

Fix #28877. Fix #213760.

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.md
    clang/lib/Sema/SemaTemplateDeduction.cpp
    clang/test/SemaTemplate/deduction-crash.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index d1856c4236020..6c23f31cd8f87 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -511,6 +511,8 @@ features cannot lower the translation-unit ABI level;
   to a subobject and is used in a context that requires an implicit conversion.
   (#GH215900)
 
+- 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
 
 - Fixed a non-deterministic ordering of unused local typedefs that made

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 21190031b95ea..48a218c090ac2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -931,6 +931,11 @@ class PackDeductionScope {
       S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
       for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
         unsigned Depth, Index;
+
+        // Function parameter packs cannot be deduced.
+        if (isa_and_present<ParmVarDecl>(
+                dyn_cast<NamedDecl *>(Unexpanded[I].first)))
+          continue;
         if (auto DI = getDepthAndIndex(Unexpanded[I]))
           std::tie(Depth, Index) = *DI;
         else

diff  --git a/clang/test/SemaTemplate/deduction-crash.cpp 
b/clang/test/SemaTemplate/deduction-crash.cpp
index e7018fd0d8338..8b6142745ac3a 100644
--- a/clang/test/SemaTemplate/deduction-crash.cpp
+++ b/clang/test/SemaTemplate/deduction-crash.cpp
@@ -177,3 +177,28 @@ 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)...); // #GH213760-f
+void g() {
+  f();
+  f<int>(1, 2);
+  f(1, 2);
+  // expected-error@-1 {{no matching function for call to 'f'}}
+  // expected-note@#GH213760-f {{candidate function [with Ts = <>] not viable: 
requires 0 arguments, but 2 were provided}}
+  f<int, int>(1, 2);
+  // expected-error@-1 {{no matching function for call to 'f'}}
+  // expected-note@#GH213760-f {{candidate function [with Ts = <int, int>] not 
viable: requires 4 arguments, but 2 were provided}}
+}
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to