[PATCH] D134529: [C++20][Clang] P2468R2 The Equality Operator You Are Looking For
Utkarsh Saxena via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 12 09:43:59 PDT 2022
usaxena95 added a comment.
In D134529#3852990 <https://reviews.llvm.org/D134529#3852990>, @erichkeane wrote:
> Note that @BertalanD noticed an issue with what I expect to be this patch: https://godbolt.org/z/Wjb9rsEYG
>
> Can someone more knowledgable about this paper please make sure it is an intended change? It seems to me that the reversing behavior of the equality operators is a little awkward here (note that commenting out != makes that 'work' again).
This is intentional. Example from https://eel.is/c++draft/over.match.oper#4
struct A {};
template<typename T> bool operator==(A, T); // #1
bool a1 = 0 == A(); // OK, calls reversed #1
template<typename T> bool operator!=(A, T);
bool a2 = 0 == A(); // error, #1 is not a rewrite target
Adding a matching `operator!=` disables reversing arguments (C++17 mode). The LHS in this case should provide a `operator==`.
The diagnostic might not be the most helpful at this point is. You can choose to
- Remove `operator!=`. Allows assuming `x==y` is equivalent to `y==x` and therefore uses the same function with reversed arguments.
- Write `s == c` instead of `c == s`.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134529/new/
https://reviews.llvm.org/D134529
More information about the cfe-commits
mailing list