Skip to content

Commit 18a0313

Browse files
committed
[Sema] Fix strict ordering in overload candidate comparisons
This is a follow-up to febf5c9 and another instance of llvm#64121. The added test only fails if Clang is built with libc++ and a enabled debug check for strict weak ordering.
1 parent fe7b5e2 commit 18a0313

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

clang/lib/Sema/SemaOverload.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -12107,9 +12107,12 @@ struct CompareOverloadCandidatesForDisplay {
1210712107
if (RFailureKind != ovl_fail_bad_deduction)
1210812108
return true;
1210912109

12110-
if (L->DeductionFailure.Result != R->DeductionFailure.Result)
12111-
return RankDeductionFailure(L->DeductionFailure)
12112-
< RankDeductionFailure(R->DeductionFailure);
12110+
if (L->DeductionFailure.Result != R->DeductionFailure.Result) {
12111+
unsigned LRank = RankDeductionFailure(L->DeductionFailure);
12112+
unsigned RRank = RankDeductionFailure(R->DeductionFailure);
12113+
if (LRank != RRank)
12114+
return LRank < RRank;
12115+
}
1211312116
} else if (RFailureKind == ovl_fail_bad_deduction)
1211412117
return false;
1211512118

clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,17 @@ namespace bad_conversion {
5252
// CHECK-NEXT: void func(double*, int, int)
5353
}
5454
}
55+
56+
namespace bad_deduction {
57+
template <class> struct templ {};
58+
template <class T> void func(templ<T>);
59+
template <class T> void func(T*);
60+
template <class T> auto func(T&) -> decltype(T().begin());
61+
template <class T> auto func(const T&) -> decltype(T().begin());
62+
63+
bool doit() {
64+
struct record {} r;
65+
func(r); // expected-error {{no matching function for call to 'func'}}
66+
// expected-note@* 4{{candidate}}
67+
}
68+
}

0 commit comments

Comments
 (0)