[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
Fri Sep 23 06:18:57 PDT 2022


usaxena95 created this revision.
Herald added a project: All.
usaxena95 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Implement
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html.

Primarily we now accept

  template<typename T> struct CRTPBase {
    bool operator==(const T&) const;
    bool operator!=(const T&) const;
  };
  struct CRTP : CRTPBase<CRTP> {};
  bool cmp_crtp = CRTP() == CRTP();
  bool cmp_crtp2 = CRTP() != CRTP();

Open questions:

1. Symmetric == member without a != defined.

`struct S{ bool operator==(const S&);};`.
In principle we should not add a reversed== in such cases as this would
never yield a better candidate and always an ambiguity with itself.
We already don't add reversed == for non-member operator with symmetric
parameters. The following is already accepted.

  struct S{};
  bool operator==(const S&, const S&);
  S() == S();

My proposal will be to do the same for member==.

2. The following example from the proposal produces error while paper suggests that this should be accepted. ``` struct D {};

template<typename T> bool operator==(D, T);     // 4
// expected-note at -1 {{candidate function template not viable: no known conversion from 'int' to 'D' for 1st argument}}
inline namespace N {

  template<typename T> bool operator!=(D, T);   // 5

}
bool d1 = 0 == D();

  I don't follow why this disallows the reverse #4.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134529

Files:
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/over/over.match/over.match.funcs/over.match.oper/p3-2a.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134529.462464.patch
Type: text/x-patch
Size: 18292 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220923/bf4db5cf/attachment-0001.bin>


More information about the cfe-commits mailing list