Looking into this further, this function is supposed to establish a *total* order, not just a strict weak order, for the overload candidates (see the isBeforeInTranslationUnit tie-breaker at the end, and the caller who uses std::sort not std::stable_sort).
On Tue, May 6, 2014 at 5:43 PM, Kaelyn Takata <[email protected]> wrote: > Author: rikka > Date: Tue May 6 19:43:38 2014 > New Revision: 208146 > > URL: http://llvm.org/viewvc/llvm-project?rev=208146&view=rev > Log: > Try harder to ensure a strict weak ordering of overload candidates that > have arity mismatches. > > Modified: > cfe/trunk/include/clang/Sema/Overload.h > cfe/trunk/lib/Sema/SemaOverload.cpp > > Modified: cfe/trunk/include/clang/Sema/Overload.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=208146&r1=208145&r2=208146&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/Sema/Overload.h (original) > +++ cfe/trunk/include/clang/Sema/Overload.h Tue May 6 19:43:38 2014 > @@ -679,6 +679,18 @@ namespace clang { > > return CanFix; > } > + > + unsigned getNumParams() const { > + if (IsSurrogate) { > + auto STy = Surrogate->getConversionType(); > + while (STy->isPointerType() || STy->isReferenceType()) > + STy = STy->getPointeeType(); > + return STy->getAs<FunctionProtoType>()->getNumParams(); > + } > + if (Function) > + return Function->getNumParams(); > + return ExplicitCallArguments; > + } > }; > > /// OverloadCandidateSet - A set of overload candidates, used in C++ > > Modified: cfe/trunk/lib/Sema/SemaOverload.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=208146&r1=208145&r2=208146&view=diff > > ============================================================================== > --- cfe/trunk/lib/Sema/SemaOverload.cpp (original) > +++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue May 6 19:43:38 2014 > @@ -9260,12 +9260,17 @@ struct CompareOverloadCandidatesForDispl > L->FailureKind == ovl_fail_too_few_arguments) { > if (R->FailureKind == ovl_fail_too_many_arguments || > R->FailureKind == ovl_fail_too_few_arguments) { > - if (!L->Function || !R->Function) return !R->Function; > - int LDist = std::abs((int)L->Function->getNumParams() - > (int)NumArgs); > - int RDist = std::abs((int)R->Function->getNumParams() - > (int)NumArgs); > - if (LDist == RDist) > - return L->FailureKind == ovl_fail_too_many_arguments && > - R->FailureKind == ovl_fail_too_few_arguments; > + int LDist = std::abs((int)L->getNumParams() - (int)NumArgs); > + int RDist = std::abs((int)R->getNumParams() - (int)NumArgs); > + if (LDist == RDist) { > + if (L->FailureKind == R->FailureKind) > + // Sort non-surrogates before surrogates. > + return !L->IsSurrogate && R->IsSurrogate; > + // Sort candidates requiring fewer parameters than there were > + // arguments given after candidates requiring more parameters > + // than there were arguments given. > + return L->FailureKind == ovl_fail_too_many_arguments; > + } > return LDist < RDist; > } > return false; > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
