diff options
author | John McCall <rjmccall@apple.com> | 2010-01-12 00:48:53 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2010-01-12 00:48:53 +0000 |
commit | bf65c0bb5705430aa7d9a16ca5d441f0cb15071d (patch) | |
tree | 6f0ba04301b8d4110b77972ccf9277399e4211a5 /lib/Sema/SemaOverload.cpp | |
parent | 1d31833450e6d2947a33cb0840d87661d92eec07 (diff) |
Sort overload results by viability.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@93215 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 74b548cb96..a7d4f372d1 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -4422,28 +4422,36 @@ void NoteAmbiguousUserConversions(Sema &S, SourceLocation OpLoc, } } -struct CompareOverloadCandidates { - SourceManager &SM; - CompareOverloadCandidates(SourceManager &SM) : SM(SM) {} +struct CompareOverloadCandidatesForDisplay { + Sema &S; + CompareOverloadCandidatesForDisplay(Sema &S) : S(S) {} bool operator()(const OverloadCandidate *L, const OverloadCandidate *R) { // Order first by viability. - if (L->Viable != R->Viable) - return L->Viable; + if (L->Viable) { + if (!R->Viable) return true; + + // TODO: introduce a tri-valued comparison for overload + // candidates. Would be more worthwhile if we had a sort + // that could exploit it. + if (S.isBetterOverloadCandidate(*L, *R)) return true; + if (S.isBetterOverloadCandidate(*R, *L)) return false; + } else if (R->Viable) + return false; // Put declared functions first. if (L->Function) { if (!R->Function) return true; - return SM.isBeforeInTranslationUnit(L->Function->getLocation(), - R->Function->getLocation()); + return S.SourceMgr.isBeforeInTranslationUnit(L->Function->getLocation(), + R->Function->getLocation()); } else if (R->Function) return false; // Then surrogates. if (L->IsSurrogate) { if (!R->IsSurrogate) return true; - return SM.isBeforeInTranslationUnit(L->Surrogate->getLocation(), - R->Surrogate->getLocation()); + return S.SourceMgr.isBeforeInTranslationUnit(L->Surrogate->getLocation(), + R->Surrogate->getLocation()); } else if (R->IsSurrogate) return false; // And builtins just come in a jumble. @@ -4470,7 +4478,8 @@ Sema::PrintOverloadCandidates(OverloadCandidateSet& CandidateSet, Cand != LastCand; ++Cand) if (Cand->Viable || OCD == OCD_AllCandidates) Cands.push_back(Cand); - std::sort(Cands.begin(), Cands.end(), CompareOverloadCandidates(SourceMgr)); + std::sort(Cands.begin(), Cands.end(), + CompareOverloadCandidatesForDisplay(*this)); bool ReportedAmbiguousConversions = false; |