[PATCH] D45680: [C++2a] Add operator<=> Rewriting - Early Attempt

Eric Fiselier via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 17 03:09:11 PDT 2018


EricWF added inline comments.


================
Comment at: lib/Sema/SemaOverload.cpp:9218-9219
+    // --- F2 is a rewritten candidate ([over.match.oper]) and F1 is not.
+    if (Cand2.getRewrittenKind() && !Cand1.getRewrittenKind())
+      return true;
+    if (Cand1.getRewrittenKind() && Cand2.getRewrittenKind() &&
----------------
rsmith wrote:
> EricWF wrote:
> > EricWF wrote:
> > > EricWF wrote:
> > > > rsmith wrote:
> > > > > You also need to check the reverse condition and return false (the "or if not that" is ... somehow ... supposed to imply that).
> > > > Hmm. So I'm wondering what is intended by the language `F1 and F2 are rewritten candidates, and F2 is a synthesized candidate with reversed order of parameters and F1 is not`. For example, what happens when comparing two distinct member functions with only one explicit parameter?
> > > > 
> > > > ```
> > > > struct T;
> > > > struct U { auto operator<=>(T); };
> > > > struct T { auto operator<=>(U); };
> > > > auto r = T{} < U{}; // Are the synthesized and rewritten overloads ambiguous? 
> > > > ```
> > > And what about 
> > > 
> > > ```
> > > struct U {};
> > > struct T { auto operator<=>(U); };
> > > auto operator<=>(U, T);
> > > auto r = T{} < U{};
> > > ```
> > Nevermind. I found the language. The implicit object parameter isn't considered in this case. 
> The parameters in scope in this rule are the parameters for the purpose of overload resolution, which include the implicit object parameter for a member function.
> 
> In your first example, both candidates have implicit conversion sequences with Exact Match rank for both parameters (and none of the ordering special cases apply), so we fall down to this tie-breaker and it selects the `T::operator<=>(U)` candidate, unless I'm missing something.
> 
> Your second example appears to receive the same treatment.
Alright. So I found the wrong language. 

I think my first case meant to have `const &` parameters and `const` methods. That way the implicit object parameter type matched the reversed parameter type. The second example was meant to demonstrate the case where the implicit object parameter type doesn't match.

What type should we be comparing against in these cases?


Repository:
  rC Clang

https://reviews.llvm.org/D45680





More information about the cfe-commits mailing list