r208146 - Try harder to ensure a strict weak ordering of overload candidates that
Richard Smith
richard at metafoo.co.uk
Tue May 6 19:35:59 PDT 2014
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 <rikka at google.com> 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
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140506/47533fe0/attachment.html>
More information about the cfe-commits
mailing list