[clang] 18a0313 - [Sema] Fix strict ordering in overload candidate comparisons
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 10 08:13:10 PST 2023
Author: Ilya Biryukov
Date: 2023-11-10T17:12:24+01:00
New Revision: 18a0313149ea2d6134e566d9190ecede96e77afb
URL: https://github.com/llvm/llvm-project/commit/18a0313149ea2d6134e566d9190ecede96e77afb
DIFF: https://github.com/llvm/llvm-project/commit/18a0313149ea2d6134e566d9190ecede96e77afb.diff
LOG: [Sema] Fix strict ordering in overload candidate comparisons
This is a follow-up to febf5c97bba7910e796041c9518fce01f31ae826 and
another instance of #64121.
The added test only fails if Clang is built with libc++ and a enabled
debug check for strict weak ordering.
Added:
Modified:
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index f97e244120612e3..858654e35cbb6bd 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -12107,9 +12107,12 @@ struct CompareOverloadCandidatesForDisplay {
if (RFailureKind != ovl_fail_bad_deduction)
return true;
- if (L->DeductionFailure.Result != R->DeductionFailure.Result)
- return RankDeductionFailure(L->DeductionFailure)
- < RankDeductionFailure(R->DeductionFailure);
+ if (L->DeductionFailure.Result != R->DeductionFailure.Result) {
+ unsigned LRank = RankDeductionFailure(L->DeductionFailure);
+ unsigned RRank = RankDeductionFailure(R->DeductionFailure);
+ if (LRank != RRank)
+ return LRank < RRank;
+ }
} else if (RFailureKind == ovl_fail_bad_deduction)
return false;
diff --git a/clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp b/clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
index 5abd048f1d136e5..79e2840583b5d65 100644
--- a/clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
+++ b/clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
@@ -52,3 +52,17 @@ namespace bad_conversion {
// CHECK-NEXT: void func(double*, int, int)
}
}
+
+namespace bad_deduction {
+ template <class> struct templ {};
+ template <class T> void func(templ<T>);
+ template <class T> void func(T*);
+ template <class T> auto func(T&) -> decltype(T().begin());
+ template <class T> auto func(const T&) -> decltype(T().begin());
+
+ bool doit() {
+ struct record {} r;
+ func(r); // expected-error {{no matching function for call to 'func'}}
+ // expected-note@* 4{{candidate}}
+ }
+}
More information about the cfe-commits
mailing list