[all-commits] [llvm/llvm-project] 460ff5: [clang] Reapply Handle templated operators with re...

Utkarsh Saxena via All-commits all-commits at lists.llvm.org
Fri Jan 12 06:03:13 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 460ff58f62456a1f3ccf61ec9cf9d10781bd41bb
      https://github.com/llvm/llvm-project/commit/460ff58f62456a1f3ccf61ec9cf9d10781bd41bb
  Author: Utkarsh Saxena <usx at google.com>
  Date:   2024-01-12 (Fri, 12 Jan 2024)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/Sema/SemaOverload.cpp
    M clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp

  Log Message:
  -----------
  [clang] Reapply Handle templated operators with reversed arguments (#72213)

Re-applies https://github.com/llvm/llvm-project/pull/69595 with extra
[diff](https://github.com/llvm/llvm-project/pull/72213/commits/79181efd0d7aef1b8396d44cdf40c0dfa4054984)
### New changes

Further relax ambiguities with a warning for member operators of a
template class (primary templates of such ops do not match). Eg:
```cpp
template <class T>
struct S {
    template <typename OtherT>
    bool operator==(const OtherT &rhs); 
};
struct A : S<int> {};
struct B : S<bool> {};
bool x = A{} == B{}; // accepted with a warning.
```

This is important for making llvm build using previous clang versions in
C++20 mode (eg: this makes the commit
e558be51bab051d1471d92e967f8a2aecc13567a keep working with a warning
instead of an error).

### Description from https://github.com/llvm/llvm-project/pull/69595

https://github.com/llvm/llvm-project/pull/68999 correctly computed
conversion sequence for reversed args to a template operator. This was a
breaking change as code, previously accepted in C++17, starts to break
in C++20.

Example:
```cpp
struct P {};
template<class S> bool operator==(const P&, const S &);

struct A : public P {};
struct B : public P {};
bool check(A a, B b) { return a == b; }  // This is now ambiguous in C++20.
```

In order to minimise widespread breakages, as a clang extension, we had
previously accepted such ambiguities with a warning
(`-Wambiguous-reversed-operator`) for non-template operators. Due to the
same reasons, we extend this relaxation for template operators.

Fixes https://github.com/llvm/llvm-project/issues/53954




More information about the All-commits mailing list