[all-commits] [llvm/llvm-project] febf5c: [Sema] Change order of displayed overloads in diag...

Ilya Biryukov via All-commits all-commits at lists.llvm.org
Mon Oct 23 04:06:51 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: febf5c97bba7910e796041c9518fce01f31ae826
      https://github.com/llvm/llvm-project/commit/febf5c97bba7910e796041c9518fce01f31ae826
  Author: Ilya Biryukov <ibiryukov at google.com>
  Date:   2023-10-23 (Mon, 23 Oct 2023)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaOverload.cpp
    A clang/test/SemaCXX/overloaded-operators-display-order-crash.cpp

  Log Message:
  -----------
  [Sema] Change order of displayed overloads in diagnostics

Make it a strict weak order.

Fixes #64121.

Current implementation uses the definition of ordering from 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 is 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.

Reviewed By: #clang-language-wg, aaron.ballman

Differential Revision: https://reviews.llvm.org/D159351




More information about the All-commits mailing list