From: Kaelyn Uhrain Date: Fri, 9 Sep 2011 21:58:49 +0000 (+0000) Subject: Add smarter sorting of overload candidates that failed template deduction. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fd641f943a7d5508858fb5f449a0f5767fa34ac7;p=clang Add smarter sorting of overload candidates that failed template deduction. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139417 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 1c78b3d113..a38b7dbd76 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -7288,6 +7288,34 @@ SourceLocation GetLocationForCandidate(const OverloadCandidate *Cand) { return SourceLocation(); } +static unsigned RankDeductionFailure( + const OverloadCandidate::DeductionFailureInfo &DFI) { + switch (DFI.Result) { + case Sema::TDK_Success: + case Sema::TDK_Incomplete: + return 1; + + case Sema::TDK_Underqualified: + case Sema::TDK_Inconsistent: + return 2; + + case Sema::TDK_SubstitutionFailure: + case Sema::TDK_NonDeducedMismatch: + return 3; + + case Sema::TDK_InstantiationDepth: + case Sema::TDK_FailedOverloadResolution: + return 4; + + case Sema::TDK_InvalidExplicitArguments: + return 5; + + case Sema::TDK_TooManyArguments: + case Sema::TDK_TooFewArguments: + return 6; + } +} + struct CompareOverloadCandidatesForDisplay { Sema &S; CompareOverloadCandidatesForDisplay(Sema &S) : S(S) {} @@ -7368,6 +7396,15 @@ struct CompareOverloadCandidatesForDisplay { } else if (R->FailureKind == ovl_fail_bad_conversion) return false; + if (L->FailureKind == ovl_fail_bad_deduction) { + if (R->FailureKind != ovl_fail_bad_deduction) + return true; + + if (L->DeductionFailure.Result != R->DeductionFailure.Result) + return RankDeductionFailure(L->DeductionFailure) + <= RankDeductionFailure(R->DeductionFailure); + } + // TODO: others? }