Candidates with arity mismatches are extra-special non-viable and need to
stand at the back of the line. Thanks to Oliver Hunt for reminding me to do this. llvm-svn: 93583
This commit is contained in:
parent
6394a6e285
commit
3712d9e391
|
@ -4582,6 +4582,14 @@ void NoteAmbiguousUserConversions(Sema &S, SourceLocation OpLoc,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SourceLocation GetLocationForCandidate(const OverloadCandidate *Cand) {
|
||||||
|
if (Cand->Function)
|
||||||
|
return Cand->Function->getLocation();
|
||||||
|
if (Cand->Surrogate)
|
||||||
|
return Cand->Surrogate->getLocation();
|
||||||
|
return SourceLocation();
|
||||||
|
}
|
||||||
|
|
||||||
struct CompareOverloadCandidatesForDisplay {
|
struct CompareOverloadCandidatesForDisplay {
|
||||||
Sema &S;
|
Sema &S;
|
||||||
CompareOverloadCandidatesForDisplay(Sema &S) : S(S) {}
|
CompareOverloadCandidatesForDisplay(Sema &S) : S(S) {}
|
||||||
|
@ -4600,22 +4608,30 @@ struct CompareOverloadCandidatesForDisplay {
|
||||||
} else if (R->Viable)
|
} else if (R->Viable)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Put declared functions first.
|
assert(L->Viable == R->Viable);
|
||||||
if (L->Function) {
|
|
||||||
if (!R->Function) return true;
|
|
||||||
return S.SourceMgr.isBeforeInTranslationUnit(L->Function->getLocation(),
|
|
||||||
R->Function->getLocation());
|
|
||||||
} else if (R->Function) return false;
|
|
||||||
|
|
||||||
// Then surrogates.
|
// Criteria by which we can sort non-viable candidates:
|
||||||
if (L->IsSurrogate) {
|
if (!L->Viable) {
|
||||||
if (!R->IsSurrogate) return true;
|
// 1. Arity mismatches come after other candidates.
|
||||||
return S.SourceMgr.isBeforeInTranslationUnit(L->Surrogate->getLocation(),
|
if (L->FailureKind == ovl_fail_too_many_arguments ||
|
||||||
R->Surrogate->getLocation());
|
L->FailureKind == ovl_fail_too_few_arguments)
|
||||||
} else if (R->IsSurrogate) return false;
|
return false;
|
||||||
|
if (R->FailureKind == ovl_fail_too_many_arguments ||
|
||||||
|
R->FailureKind == ovl_fail_too_few_arguments)
|
||||||
|
return true;
|
||||||
|
|
||||||
// And builtins just come in a jumble.
|
// TODO: others?
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
// Sort everything else by location.
|
||||||
|
SourceLocation LLoc = GetLocationForCandidate(L);
|
||||||
|
SourceLocation RLoc = GetLocationForCandidate(R);
|
||||||
|
|
||||||
|
// Put candidates without locations (e.g. builtins) at the end.
|
||||||
|
if (LLoc.isInvalid()) return false;
|
||||||
|
if (RLoc.isInvalid()) return true;
|
||||||
|
|
||||||
|
return S.SourceMgr.isBeforeInTranslationUnit(LLoc, RLoc);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue