usx95 wrote:

I wanted to note down the challenges of landing this and the strategy to move 
forward.

#### Challenges
* Landing this would make old code ambiguous 
([example](https://godbolt.org/z/11331KW6e)). This is not unexpected, and it is 
ambiguous in C++20.
* This would break LLVM in C++20 
([breakage](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/ADT/STLExtras.h#L1293-L1303)).
 We do not want to break LLVM at head.
* But it would not be possible to resolve ambiguity also for **template friend 
functions** because of 
[cwg2804](https://cplusplus.github.io/CWG/issues/2804.html).
* In order to resolve this ambiguity, one solution is to make the operator 
non-friend and add a matching `operator!=` 
([P2468R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html)).
 This is done in https://github.com/llvm/llvm-project/pull/72348. The solution 
would look like:
  ```cpp
  namespace N{
  struct P {};
  template<class S> bool operator==(const P&, const S &);
  template<class S> bool operator!=(const P&, const S &);
  struct A : public P {};
  struct B : public P {};
  }
  bool x = N::A{} == N::B{};
  ```
* The catch is that clang only recently fixed its  
([P2468R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html))
 implementation for `operators==` found through ADL in 
https://github.com/llvm/llvm-project/commit/9330261143ccbe947ef0687fd20747ba47f26879.
* Without the above fix, LLVM would still be broken in clang-17 (because 
clang-17 doesn't have 
https://github.com/llvm/llvm-project/commit/9330261143ccbe947ef0687fd20747ba47f26879).

#### Strategy
1. Wait for cherrypicking 
https://github.com/llvm/llvm-project-release-prs/pull/778 into clang-17.0.6.
2. Land https://github.com/llvm/llvm-project/pull/72348 to unbreak LLVM.
3. Update the latest revision to build LLVM in C++20 to **17.0.6**.
4. Land this PR https://github.com/llvm/llvm-project/pull/72213 
5. Implement [cwg2804](https://cplusplus.github.io/CWG/issues/2804.html) 
proposal when finalised.
6. **clang-18** would have correct behaviour for template operators, i.e., 
correct ambiguities surfaced with the option of resolving through adding 
matching `operator!=`.


https://github.com/llvm/llvm-project/pull/72213
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to