<div dir="ltr"><div dir="ltr">On Thu, 5 Mar 2020 at 11:41, Robinson, Paul via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Richard Smith made a patch in f041e9ad for CWG2352.<br>
> As a consequence of this patch, we had an obscure test failure,<br>
> and it's not clear to me that it's an intentional consequence.<br>
> So I figured I'd ask here.<br>
><br>
> Reduced test case:<br>
<br>
Slightly edited and expanded test case:<br>
<br>
bool foo(void * const * const *       &&) { return false; } // new choice<br>
bool foo(void *       * const * const &)  { return true; }  // old choice<br>
bool bar() {<br>
 return foo(reinterpret_cast<void***>(2));<br>
}<br></blockquote><div><br></div><div>I'm not entirely sure how we were coming up with the old answer, but the new answer is correct: binding an rvalue reference to an rvalue is preferred over binding an lvalue reference.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
// A couple of additional cases:<br>
void*** p;<br>
void*** q() { return p; }<br>
bool func1() { return foo(p); } // old and new both call '&' overload<br>
bool func2() { return foo(q()); } // old calls '&', new calls '&&'<br></blockquote><div><br></div><div>Here, q() is an rvalue, so we prefer binding an rvalue reference. p is an lvalue, so that rule doesn't apply and we prefer binding the lvalue reference because it binds to a less-qualified type.</div><div><br></div><div>I believe the new Clang behavior is following the rules described in C++ [over.ics.rank] paragraph 3.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
So it looks like it matters whether the argument is an expression?<br>
--paulr<br>
<br>
<br>
> Prior to the patch, the compiler selected the second overload;<br>
> after the patch, it selects the first overload.  Apparently there's<br>
> some subtle difference in the preferred-ness of one over the other,<br>
> and AFAICT the const-nesses aren't supposed to factor in any more?<br>
> so it's about the &-ref versus the &&-ref?<br>
><br>
> As I said, mainly I want to make sure this was intentional; if it<br>
> is, we can fiddle our test and that's the end of it.  But if it's<br>
> not intentional, this change is in the almost-final Clang 10.0<br>
> release, and might want to be fixed before it goes out.<br>
><br>
> Thanks,<br>
> --paulr<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div>