[PATCH] D159351: [Sema] Change order of displayed overloads in diagnostics
Ilya Biryukov via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 1 04:50:44 PDT 2023
ilya-biryukov created this revision.
Herald added a project: All.
ilya-biryukov requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Make it a strict weak order.
Fixes #64121.
Current implementation uses the definition the definition of ordering
in the C++ standard. The definition provides only a partial order and
cannot be used in sorting algorithms.
The debug builds of libc++ are capable of detecting that problem
and this failure was found when building Clang with libc++ and
those extra checks enabled, see #64121.
The new ordering takes attempts to be a strict weak order and still
pushes most interesting functions to the start of the list.
In some cases, it leads to better results, e.g.
struct Foo {
operator int();
operator const char*();
};
void test() { Foo() - Foo(); }
Now produces a list with two most relevant builtin operators at the top,
i.e. `operator-(int, int)` and `operator-(const char*, const char*)`.
Previously `operator-(const char*, const char*)` was the first element,
but `operator-(int, int)` was only the 13th element in the output.
This is a consequence of `stable_sort` now being able to compare those
two candidates, which are indistinguishable in the semantic partial order
despite being two local minimums in their respective comparable
subsets.
However, new implementation does not take into account some aspects of
C++ semantics, e.g. which function template is more specialized. This
can also lead to worse ordering sometimes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D159351
Files:
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159351.555334.patch
Type: text/x-patch
Size: 6307 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230901/7426d6dc/attachment.bin>
More information about the cfe-commits
mailing list