[llvm-branch-commits] [clang] [clang] Finish implementation of P0522 (PR #96023)
Matheus Izvekov via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jun 19 09:15:12 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
----------------
mizvekov wrote:
The pre-existing error we have used for this is `MiscellaneousDeductionFailure`. `IncompletePack` means something else, it's used when we have an already expanded pack and we failed to deduce all elements of it.
This is a separate thing we have to fix, basically get rid of the `MiscellaneousDeductionFailure`, create new representations for all the separate things it was used for, and remove the generic `bad deduction` diagnostic.
But this would touch tests far outside of the scope of this patch, so I think it's best left for a separate PR.
https://github.com/llvm/llvm-project/pull/96023
More information about the llvm-branch-commits
mailing list