Skip to content

Commit

Permalink
[Sema] Fix strict ordering in overload candidate comparisons
Browse files Browse the repository at this point in the history
This is a follow-up to febf5c9 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.
  • Loading branch information
ilya-biryukov committed Nov 10, 2023
1 parent fe7b5e2 commit 18a0313
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
9 changes: 6 additions & 3 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
14 changes: 14 additions & 0 deletions clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
}

0 comments on commit 18a0313

Please sign in to comment.