When template argument deduction fails because the call had too
many/too few arguments, use the same diagnostic we use for arity mismatches in non-templates (but note that it's a function template). llvm-svn: 103341
This commit is contained in:
parent
3626a5cac2
commit
02eb4835ce
|
@ -1069,9 +1069,9 @@ def note_ovl_candidate_arity : Note<"candidate "
|
||||||
"%select{function|function|constructor|function|function|constructor|"
|
"%select{function|function|constructor|function|function|constructor|"
|
||||||
"constructor (the implicit default constructor)|"
|
"constructor (the implicit default constructor)|"
|
||||||
"constructor (the implicit copy constructor)|"
|
"constructor (the implicit copy constructor)|"
|
||||||
"function (the implicit copy assignment operator)}0 not viable: requires"
|
"function (the implicit copy assignment operator)}0 %select{|template }1"
|
||||||
"%select{ at least| at most|}2 %3 argument%s3, but %4 %plural{1:was|:were}4 "
|
"not viable: requires%select{ at least| at most|}2 %3 argument%s3, but %4 "
|
||||||
"provided">;
|
"%plural{1:was|:were}4 provided">;
|
||||||
|
|
||||||
def note_ovl_candidate_deleted : Note<
|
def note_ovl_candidate_deleted : Note<
|
||||||
"candidate %select{function|function|constructor|"
|
"candidate %select{function|function|constructor|"
|
||||||
|
|
|
@ -5056,16 +5056,21 @@ void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
|
||||||
unsigned MinParams = Fn->getMinRequiredArguments();
|
unsigned MinParams = Fn->getMinRequiredArguments();
|
||||||
|
|
||||||
// at least / at most / exactly
|
// at least / at most / exactly
|
||||||
|
// FIXME: variadic templates "at most" should account for parameter packs
|
||||||
unsigned mode, modeCount;
|
unsigned mode, modeCount;
|
||||||
if (NumFormalArgs < MinParams) {
|
if (NumFormalArgs < MinParams) {
|
||||||
assert(Cand->FailureKind == ovl_fail_too_few_arguments);
|
assert((Cand->FailureKind == ovl_fail_too_few_arguments) ||
|
||||||
|
(Cand->FailureKind == ovl_fail_bad_deduction &&
|
||||||
|
Cand->DeductionFailure.Result == Sema::TDK_TooFewArguments));
|
||||||
if (MinParams != FnTy->getNumArgs() || FnTy->isVariadic())
|
if (MinParams != FnTy->getNumArgs() || FnTy->isVariadic())
|
||||||
mode = 0; // "at least"
|
mode = 0; // "at least"
|
||||||
else
|
else
|
||||||
mode = 2; // "exactly"
|
mode = 2; // "exactly"
|
||||||
modeCount = MinParams;
|
modeCount = MinParams;
|
||||||
} else {
|
} else {
|
||||||
assert(Cand->FailureKind == ovl_fail_too_many_arguments);
|
assert((Cand->FailureKind == ovl_fail_too_many_arguments) ||
|
||||||
|
(Cand->FailureKind == ovl_fail_bad_deduction &&
|
||||||
|
Cand->DeductionFailure.Result == Sema::TDK_TooManyArguments));
|
||||||
if (MinParams != FnTy->getNumArgs())
|
if (MinParams != FnTy->getNumArgs())
|
||||||
mode = 1; // "at most"
|
mode = 1; // "at most"
|
||||||
else
|
else
|
||||||
|
@ -5077,7 +5082,8 @@ void DiagnoseArityMismatch(Sema &S, OverloadCandidate *Cand,
|
||||||
OverloadCandidateKind FnKind = ClassifyOverloadCandidate(S, Fn, Description);
|
OverloadCandidateKind FnKind = ClassifyOverloadCandidate(S, Fn, Description);
|
||||||
|
|
||||||
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
|
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_arity)
|
||||||
<< (unsigned) FnKind << Description << mode << modeCount << NumFormalArgs;
|
<< (unsigned) FnKind << (Fn->getDescribedFunctionTemplate() != 0) << mode
|
||||||
|
<< modeCount << NumFormalArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Diagnose a failed template-argument deduction.
|
/// Diagnose a failed template-argument deduction.
|
||||||
|
@ -5121,13 +5127,16 @@ void DiagnoseBadDeduction(Sema &S, OverloadCandidate *Cand,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case Sema::TDK_TooManyArguments:
|
||||||
|
case Sema::TDK_TooFewArguments:
|
||||||
|
DiagnoseArityMismatch(S, Cand, NumArgs);
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: diagnose these individually, then kill off
|
// TODO: diagnose these individually, then kill off
|
||||||
// note_ovl_candidate_bad_deduction, which is uselessly vague.
|
// note_ovl_candidate_bad_deduction, which is uselessly vague.
|
||||||
case Sema::TDK_InstantiationDepth:
|
case Sema::TDK_InstantiationDepth:
|
||||||
case Sema::TDK_SubstitutionFailure:
|
case Sema::TDK_SubstitutionFailure:
|
||||||
case Sema::TDK_NonDeducedMismatch:
|
case Sema::TDK_NonDeducedMismatch:
|
||||||
case Sema::TDK_TooManyArguments:
|
|
||||||
case Sema::TDK_TooFewArguments:
|
|
||||||
case Sema::TDK_InvalidExplicitArguments:
|
case Sema::TDK_InvalidExplicitArguments:
|
||||||
case Sema::TDK_FailedOverloadResolution:
|
case Sema::TDK_FailedOverloadResolution:
|
||||||
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_deduction);
|
S.Diag(Fn->getLocation(), diag::note_ovl_candidate_bad_deduction);
|
||||||
|
|
|
@ -15,7 +15,7 @@ void k2() {
|
||||||
g(b); // OK: cv-qualifiers are ignored on template parameter types
|
g(b); // OK: cv-qualifiers are ignored on template parameter types
|
||||||
}
|
}
|
||||||
|
|
||||||
template<short s> void h(int (&)[s]); // expected-note{{failed template argument deduction}}
|
template<short s> void h(int (&)[s]); // expected-note{{candidate function template not viable: requires 1 argument, but 2 were provided}}
|
||||||
void k3() {
|
void k3() {
|
||||||
int array[5];
|
int array[5];
|
||||||
h(array);
|
h(array);
|
||||||
|
|
Loading…
Reference in New Issue