[llvm-branch-commits] [clang] [clang] Finish implementation of P0522 (PR #96023)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 19 02:42:37 PDT 2024
================
@@ -2513,49 +2545,76 @@ DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams,
TemplateDeductionInfo &Info,
SmallVectorImpl<DeducedTemplateArgument> &Deduced,
bool NumberOfArgumentsMustMatch, PackFold PackFold) {
- if (PackFold == PackFold::ArgumentToParameter)
- std::swap(Ps, As);
+ bool FoldPackParameter = PackFold == PackFold::ParameterToArgument ||
+ PackFold == PackFold::Both,
+ FoldPackArgument = PackFold == PackFold::ArgumentToParameter ||
+ PackFold == PackFold::Both;
+
// C++0x [temp.deduct.type]p9:
// If the template argument list of P contains a pack expansion that is not
// the last template argument, the entire template argument list is a
// non-deduced context.
- if (hasPackExpansionBeforeEnd(Ps))
+ if (FoldPackParameter && hasPackExpansionBeforeEnd(Ps))
+ return TemplateDeductionResult::Success;
+
+ if (FoldPackArgument && hasPackExpansionBeforeEnd(As))
return TemplateDeductionResult::Success;
// C++0x [temp.deduct.type]p9:
// If P has a form that contains <T> or <i>, then each argument Pi of the
// respective template argument list P is compared with the corresponding
// argument Ai of the corresponding template argument list of A.
- unsigned ArgIdx = 0, ParamIdx = 0;
- for (; hasTemplateArgumentForDeduction(Ps, ParamIdx); ++ParamIdx) {
- const TemplateArgument &P = Ps[ParamIdx];
- if (!P.isPackExpansion()) {
+ for (unsigned ArgIdx = 0, ParamIdx = 0; /**/; /**/) {
+ if (!hasTemplateArgumentForDeduction(Ps, ParamIdx))
+ return !FoldPackParameter && NumberOfArgumentsMustMatch &&
+ hasTemplateArgumentForDeduction(As, ArgIdx) &&
+ !As[ArgIdx].isPackExpansion()
+ ? TemplateDeductionResult::MiscellaneousDeductionFailure
+ : TemplateDeductionResult::Success;
+
+ if (!Ps[ParamIdx].isPackExpansion()) {
// The simple case: deduce template arguments by matching Pi and Ai.
// Check whether we have enough arguments.
if (!hasTemplateArgumentForDeduction(As, ArgIdx))
- return NumberOfArgumentsMustMatch
+ return !FoldPackArgument && NumberOfArgumentsMustMatch
? TemplateDeductionResult::MiscellaneousDeductionFailure
: TemplateDeductionResult::Success;
- // C++1z [temp.deduct.type]p9:
- // During partial ordering, if Ai was originally a pack expansion [and]
- // Pi is not a pack expansion, template argument deduction fails.
- if (As[ArgIdx].isPackExpansion())
- return TemplateDeductionResult::MiscellaneousDeductionFailure;
+ if (As[ArgIdx].isPackExpansion()) {
+ // C++1z [temp.deduct.type]p9:
+ // During partial ordering, if Ai was originally a pack expansion
+ // [and] Pi is not a pack expansion, template argument deduction
+ // fails.
+ if (!FoldPackArgument)
+ return TemplateDeductionResult::MiscellaneousDeductionFailure;
+
+ for (TemplateArgument Pattern = As[ArgIdx].getPackExpansionPattern();
+ /**/;
+ /**/) {
----------------
cor3ntin wrote:
Formatting is super weird. We might as well use while loop here (and above)
https://github.com/llvm/llvm-project/pull/96023
More information about the llvm-branch-commits
mailing list