]> granicus.if.org Git - clang/commitdiff
Add smarter sorting of overload candidates that failed template deduction.
authorKaelyn Uhrain <rikka@google.com>
Fri, 9 Sep 2011 21:58:49 +0000 (21:58 +0000)
committerKaelyn Uhrain <rikka@google.com>
Fri, 9 Sep 2011 21:58:49 +0000 (21:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@139417 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaOverload.cpp

index 1c78b3d11381544e7eb56bfd33cab5561f071a4c..a38b7dbd76017cb40c0398f128e5e1d7a491db3f 100644 (file)
@@ -7288,6 +7288,34 @@ SourceLocation GetLocationForCandidate(const OverloadCandidate *Cand) {
   return SourceLocation();
 }
 
+static unsigned RankDeductionFailure(
+    const OverloadCandidate::DeductionFailureInfo &DFI) {
+  switch (DFI.Result) {
+  case Sema::TDK_Success:
+  case Sema::TDK_Incomplete:
+    return 1;
+
+  case Sema::TDK_Underqualified:
+  case Sema::TDK_Inconsistent:
+    return 2;
+
+  case Sema::TDK_SubstitutionFailure:
+  case Sema::TDK_NonDeducedMismatch:
+    return 3;
+
+  case Sema::TDK_InstantiationDepth:
+  case Sema::TDK_FailedOverloadResolution:
+    return 4;
+
+  case Sema::TDK_InvalidExplicitArguments:
+    return 5;
+
+  case Sema::TDK_TooManyArguments:
+  case Sema::TDK_TooFewArguments:
+    return 6;
+  }
+}
+
 struct CompareOverloadCandidatesForDisplay {
   Sema &S;
   CompareOverloadCandidatesForDisplay(Sema &S) : S(S) {}
@@ -7368,6 +7396,15 @@ struct CompareOverloadCandidatesForDisplay {
       } else if (R->FailureKind == ovl_fail_bad_conversion)
         return false;
 
+      if (L->FailureKind == ovl_fail_bad_deduction) {
+        if (R->FailureKind != ovl_fail_bad_deduction)
+          return true;
+
+        if (L->DeductionFailure.Result != R->DeductionFailure.Result)
+          return RankDeductionFailure(L->DeductionFailure)
+              <= RankDeductionFailure(R->DeductionFailure);
+      }
+
       // TODO: others?
     }