[clang] [Clang][Sema][TemplateDeduction] Skip pack expansion type at the end of default template argument list if unneeded (PR #94659)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 11:59:01 PDT 2024
https://github.com/yozhu created https://github.com/llvm/llvm-project/pull/94659
If default argument list has one more element than actual argument list and the last default argument is a pack expansion, we can ignore it. This is to fix a failed assertion:
clang: llvm-project/clang/lib/Sema/SemaTemplateDeduction.cpp:596: TemplateDeductionResult DeduceTemplateArguments(Sema &, TemplateParameterList *, TemplateName, TemplateName, TemplateDeductionInfo &, ArrayRef<TemplateArgument>, SmallVectorImpl<DeducedTemplateArgument> &): Assertion `DefaultArguments.size() <= As->size()' failed.
>From 3dc8d5a0149a3fd0e3ca70d06f2ecc786bdc18fa Mon Sep 17 00:00:00 2001
From: YongKang Zhu <yongzhu at fb.com>
Date: Thu, 6 Jun 2024 11:51:51 -0700
Subject: [PATCH] [Clang][Sema][TemplateDeduction] Skip pack expansion type at
the end of default argument list if actual argument list's length is one less
---
clang/lib/Sema/SemaTemplateDeduction.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 1011db2d2830d..e66f35c38dfda 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -593,9 +593,15 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
TemplateParameterList *As = TempArg->getTemplateParameters();
if (DefaultArguments.size() != 0) {
- assert(DefaultArguments.size() <= As->size());
+ if ((DefaultArguments.size() > As->size()) &&
+ (DefaultArguments.size() != As->size() + 1 ||
+ DefaultArguments.back().getKind() != TemplateArgument::Type ||
+ !isa<PackExpansionType>(DefaultArguments.back().getAsType()))) {
+ return TemplateDeductionResult::TooFewArguments;
+ }
SmallVector<NamedDecl *, 4> Params(As->size());
- for (unsigned I = 0; I < DefaultArguments.size(); ++I)
+ for (unsigned I = 0;
+ I < std::min((size_t)As->size(), DefaultArguments.size()); ++I)
Params[I] = getTemplateParameterWithDefault(S, As->getParam(I),
DefaultArguments[I]);
for (unsigned I = DefaultArguments.size(); I < As->size(); ++I)
More information about the cfe-commits
mailing list