Fix argument numbering confusion when diagnosing a non-viable operator().

This could lead to crashes if operator() is a variadic template, as we
could end up asking for an out-of-bounds argument.
This commit is contained in:
Richard Smith 2019-10-29 13:06:34 -07:00
parent d46c65592e
commit 52590319a2
2 changed files with 11 additions and 2 deletions

View File

@ -11001,7 +11001,8 @@ CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand,
!isa<CXXConstructorDecl>(Cand->Function)) {
// Conversion 0 is 'this', which doesn't have a corresponding parameter.
ConvIdx = 1;
if (CSK == OverloadCandidateSet::CSK_Operator)
if (CSK == OverloadCandidateSet::CSK_Operator &&
Cand->Function->getDeclName().getCXXOverloadedOperator() != OO_Call)
// Argument 0 is 'this', which doesn't have a corresponding parameter.
ArgIdx = 1;
}
@ -11016,9 +11017,10 @@ CompleteNonViableCandidate(Sema &S, OverloadCandidate *Cand,
for (unsigned ParamIdx = Reversed ? ParamTypes.size() - 1 : 0;
ConvIdx != ConvCount;
++ConvIdx, ++ArgIdx, ParamIdx += (Reversed ? -1 : 1)) {
assert(ArgIdx < Args.size() && "no argument for this arg conversion");
if (Cand->Conversions[ConvIdx].isInitialized()) {
// We've already checked this conversion.
} else if (ArgIdx < ParamTypes.size()) {
} else if (ParamIdx < ParamTypes.size()) {
if (ParamTypes[ParamIdx]->isDependentType())
Cand->Conversions[ConvIdx].setAsIdentityConversion(
Args[ArgIdx]->getType());

View File

@ -114,3 +114,10 @@ namespace b7398190 {
const S *p;
int k = p->f(); // expected-error {{no matching member function for call to 'f'}}
}
void member_call_op_template(int *p) {
// Ensure that we don't get confused about relative parameter / argument
// indexing here.
[](int, int, auto...){}(p, p); // expected-error {{no matching function}} expected-note {{no known conversion}}
}