Fix OverloadCandidateSet::clear to not leak PartialDiagnostics, found by Samuel
Panzer. I've not been able to trigger a failure caused by this, so no test yet.
Also included is a small change from Paul Robinson to only consider the
FailureKind if the overload candidate did actually fail.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160470 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Sema/Overload.h b/include/clang/Sema/Overload.h
index 4e39678..d2fc285 100644
--- a/include/clang/Sema/Overload.h
+++ b/include/clang/Sema/Overload.h
@@ -753,14 +753,7 @@
     
   public:
     OverloadCandidateSet(SourceLocation Loc) : Loc(Loc), NumInlineSequences(0){}
-    ~OverloadCandidateSet() {
-      for (iterator i = begin(), e = end(); i != e; ++i) {
-        for (unsigned ii = 0, ie = i->NumConversions; ii != ie; ++ii)
-          i->Conversions[ii].~ImplicitConversionSequence();
-        if (i->FailureKind == ovl_fail_bad_deduction)
-          i->DeductionFailure.Destroy();
-      }
-    }
+    ~OverloadCandidateSet() { clear(); }
 
     SourceLocation getLocation() const { return Loc; }
 
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index f045a2b..9420b73 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -735,9 +735,12 @@
 }
 
 void OverloadCandidateSet::clear() {
-  for (iterator i = begin(), e = end(); i != e; ++i)
+  for (iterator i = begin(), e = end(); i != e; ++i) {
     for (unsigned ii = 0, ie = i->NumConversions; ii != ie; ++ii)
       i->Conversions[ii].~ImplicitConversionSequence();
+    if (!i->Viable && i->FailureKind == ovl_fail_bad_deduction)
+      i->DeductionFailure.Destroy();
+  }
   NumInlineSequences = 0;
   Candidates.clear();
   Functions.clear();