<div dir="ltr">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).</div>
<div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, May 6, 2014 at 5:43 PM, Kaelyn Takata <span dir="ltr"><<a href="mailto:rikka@google.com" target="_blank">rikka@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: rikka<br>
Date: Tue May  6 19:43:38 2014<br>
New Revision: 208146<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=208146&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=208146&view=rev</a><br>
Log:<br>
Try harder to ensure a strict weak ordering of overload candidates that<br>
have arity mismatches.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Sema/Overload.h<br>
    cfe/trunk/lib/Sema/SemaOverload.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Overload.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=208146&r1=208145&r2=208146&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=208146&r1=208145&r2=208146&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Overload.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Overload.h Tue May  6 19:43:38 2014<br>
@@ -679,6 +679,18 @@ namespace clang {<br>
<br>
       return CanFix;<br>
     }<br>
+<br>
+    unsigned getNumParams() const {<br>
+      if (IsSurrogate) {<br>
+        auto STy = Surrogate->getConversionType();<br>
+        while (STy->isPointerType() || STy->isReferenceType())<br>
+          STy = STy->getPointeeType();<br>
+        return STy->getAs<FunctionProtoType>()->getNumParams();<br>
+      }<br>
+      if (Function)<br>
+        return Function->getNumParams();<br>
+      return ExplicitCallArguments;<br>
+    }<br>
   };<br>
<br>
   /// OverloadCandidateSet - A set of overload candidates, used in C++<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=208146&r1=208145&r2=208146&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=208146&r1=208145&r2=208146&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue May  6 19:43:38 2014<br>
@@ -9260,12 +9260,17 @@ struct CompareOverloadCandidatesForDispl<br>
           L->FailureKind == ovl_fail_too_few_arguments) {<br>
         if (R->FailureKind == ovl_fail_too_many_arguments ||<br>
             R->FailureKind == ovl_fail_too_few_arguments) {<br>
-          if (!L->Function || !R->Function) return !R->Function;<br>
-          int LDist = std::abs((int)L->Function->getNumParams() - (int)NumArgs);<br>
-          int RDist = std::abs((int)R->Function->getNumParams() - (int)NumArgs);<br>
-          if (LDist == RDist)<br>
-            return L->FailureKind == ovl_fail_too_many_arguments &&<br>
-                   R->FailureKind == ovl_fail_too_few_arguments;<br>
+          int LDist = std::abs((int)L->getNumParams() - (int)NumArgs);<br>
+          int RDist = std::abs((int)R->getNumParams() - (int)NumArgs);<br>
+          if (LDist == RDist) {<br>
+            if (L->FailureKind == R->FailureKind)<br>
+              // Sort non-surrogates before surrogates.<br>
+              return !L->IsSurrogate && R->IsSurrogate;<br>
+            // Sort candidates requiring fewer parameters than there were<br>
+            // arguments given after candidates requiring more parameters<br>
+            // than there were arguments given.<br>
+            return L->FailureKind == ovl_fail_too_many_arguments;<br>
+          }<br>
           return LDist < RDist;<br>
         }<br>
         return false;<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>