From: Kaelyn Takata Date: Wed, 7 May 2014 00:43:38 +0000 (+0000) Subject: Try harder to ensure a strict weak ordering of overload candidates that X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=695bd88b268d5ab9d7d1af712657d7b0fc08cb0b;p=clang Try harder to ensure a strict weak ordering of overload candidates that have arity mismatches. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208146 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h index d6dbd1226a..9618f8f108 100644 --- a/include/clang/Sema/Overload.h +++ b/include/clang/Sema/Overload.h @@ -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()->getNumParams(); + } + if (Function) + return Function->getNumParams(); + return ExplicitCallArguments; + } }; /// OverloadCandidateSet - A set of overload candidates, used in C++ diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 7f9e0ecd96..51d130c685 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -9260,12 +9260,17 @@ struct CompareOverloadCandidatesForDisplay { 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;