[clang] cfacf9a - PR44761: Fix fallback to later tiebreakers if two non-template functions

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 4 12:21:54 PST 2020


Author: Richard Smith
Date: 2020-02-04T12:21:42-08:00
New Revision: cfacf9ae20b8c97a428f118a2720bc109ba6a143

URL: https://github.com/llvm/llvm-project/commit/cfacf9ae20b8c97a428f118a2720bc109ba6a143
DIFF: https://github.com/llvm/llvm-project/commit/cfacf9ae20b8c97a428f118a2720bc109ba6a143.diff

LOG: PR44761: Fix fallback to later tiebreakers if two non-template functions
are equally constrained.

Added: 
    clang/test/CXX/over/over.match/over.match.best/p2.cpp

Modified: 
    clang/lib/Sema/SemaOverload.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 00542bf25006..9b89bac0db39 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -9588,17 +9588,15 @@ bool clang::isBetterOverloadCandidate(
       if (RC1 && RC2) {
         bool AtLeastAsConstrained1, AtLeastAsConstrained2;
         if (S.IsAtLeastAsConstrained(Cand1.Function, {RC1}, Cand2.Function,
-                                     {RC2}, AtLeastAsConstrained1))
-          return false;
-        if (!AtLeastAsConstrained1)
-          return false;
-        if (S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function,
+                                     {RC2}, AtLeastAsConstrained1) ||
+            S.IsAtLeastAsConstrained(Cand2.Function, {RC2}, Cand1.Function,
                                      {RC1}, AtLeastAsConstrained2))
           return false;
-        if (!AtLeastAsConstrained2)
-          return true;
-      } else if (RC1 || RC2)
+        if (AtLeastAsConstrained1 != AtLeastAsConstrained2)
+          return AtLeastAsConstrained1;
+      } else if (RC1 || RC2) {
         return RC1 != nullptr;
+      }
     }
   }
 

diff  --git a/clang/test/CXX/over/over.match/over.match.best/p2.cpp b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
new file mode 100644
index 000000000000..3a4443665576
--- /dev/null
+++ b/clang/test/CXX/over/over.match/over.match.best/p2.cpp
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++2a -verify %s
+
+namespace PR44761 {
+  template<typename T> concept X = (sizeof(T) == sizeof(T));
+
+  template<typename T> struct A {
+    bool operator<(const A&) const & requires X<T>; // #1
+    int operator<=>(const A&) const & requires X<T> && X<int> = delete; // #2
+  };
+  bool k1 = A<int>() < A<int>(); // not ordered by constraints: prefer non-rewritten form
+  bool k2 = A<float>() < A<float>(); // prefer more-constrained 'operator<=>'
+  // expected-error at -1 {{deleted}}
+  // expected-note@#1 {{candidate}}
+  // expected-note@#2 {{candidate function has been explicitly deleted}}
+  // expected-note@#2 {{candidate function (with reversed parameter order) has been explicitly deleted}}
+}


        


More information about the cfe-commits mailing list