summaryrefslogtreecommitdiffstats
path: root/lib/Sema/SemaOverload.cpp
diff options
context:
space:
mode:
authorKaelyn Takata <rikka@google.com>2014-05-07 00:43:38 +0000
committerKaelyn Takata <rikka@google.com>2014-05-07 00:43:38 +0000
commit695bd88b268d5ab9d7d1af712657d7b0fc08cb0b (patch)
tree4a4586a33fb2a617c3528883a9d15899e81089bc /lib/Sema/SemaOverload.cpp
parent3f4e8a5acd4c1d41607e4c396f7a7fa38c0b16bf (diff)
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
Diffstat (limited to 'lib/Sema/SemaOverload.cpp')
-rw-r--r--lib/Sema/SemaOverload.cpp17
1 files changed, 11 insertions, 6 deletions
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;