Discussion:
Where in the standard does it say that a user-defined conversion sequence that binds an rvalue reference is better than one that binds an lvalue reference?
(too old to reply)
Brian Bi
2018-11-14 18:12:20 UTC
Permalink
I asked this question on Stack Overflow:
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi

It concerns the following code. The question is whether there's a rule in
the standard that implies that the S&& overload shall be selected over the
const S& overload.

#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&)
{ std::puts("S&&"); }int main() {
f(42);}

It doesn't seem to have received a response there. I also looked through
the CWG issue list by section, and couldn't find anything relevant there.
Am I just missing something?
--
*Brian Bi*
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Richard Smith
2018-11-14 22:43:54 UTC
Permalink
Post by Brian Bi
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi
It concerns the following code. The question is whether there's a rule in
the standard that implies that the S&& overload shall be selected over the
const S& overload.
#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&) { std::puts("S&&"); }int main() {
f(42);}
It doesn't seem to have received a response there. I also looked through
the CWG issue list by section, and couldn't find anything relevant there.
Am I just missing something?
http://eel.is/c++draft/over.ics.rank#3.2.3 orders the second standard
conversion sequences of the user-defined conversion sequences here.
http://eel.is/c++draft/over.ics.rank#3.3 orders the user-defined conversion
sequences based on the order of the second standard conversion sequences.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Brian Bi
2018-11-14 22:48:09 UTC
Permalink
Post by Richard Smith
Post by Brian Bi
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi
It concerns the following code. The question is whether there's a rule in
the standard that implies that the S&& overload shall be selected over the
const S& overload.
#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&) { std::puts("S&&"); }int main() {
f(42);}
It doesn't seem to have received a response there. I also looked through
the CWG issue list by section, and couldn't find anything relevant there.
Am I just missing something?
http://eel.is/c++draft/over.ics.rank#3.2.3 orders the second standard
conversion sequences of the user-defined conversion sequences here.
http://eel.is/c++draft/over.ics.rank#3.3 orders the user-defined
conversion sequences based on the order of the second standard conversion
sequences.
http://eel.is/c++draft/over.ics.ref#2 appears to imply that in both of
the user-defined conversion sequences, the second standard conversion is
the identity conversion.
--
*Brian Bi*
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Richard Smith
2018-11-14 23:19:54 UTC
Permalink
Post by Brian Bi
Post by Richard Smith
Post by Brian Bi
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi
It concerns the following code. The question is whether there's a rule
in the standard that implies that the S&& overload shall be selected over
the const S& overload.
#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&) { std::puts("S&&"); }int main() {
f(42);}
It doesn't seem to have received a response there. I also looked through
the CWG issue list by section, and couldn't find anything relevant there.
Am I just missing something?
http://eel.is/c++draft/over.ics.rank#3.2.3 orders the second standard
conversion sequences of the user-defined conversion sequences here.
http://eel.is/c++draft/over.ics.rank#3.3 orders the user-defined
conversion sequences based on the order of the second standard conversion
sequences.
http://eel.is/c++draft/over.ics.ref#2 appears to imply that in both of
the user-defined conversion sequences, the second standard conversion is
the identity conversion.
I think that's true but irrelevant. /3.2.3 is not dependent on whether the
standard conversion sequences have different categories. Consider this
simpler example:

void f();
int g(void (&)()); // #1
void g(void (&&)()); // #2
int v = g(f);

Here, this calls #1, because the standard conversion sequence for #1 is
better than that for #2, by [over.ics.rank]/3.2.4. And that happens even
though the standard conversion sequence is an identity conversion for the
argument in both cases.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Brian Bi
2018-11-15 03:46:19 UTC
Permalink
Post by Richard Smith
Post by Richard Smith
Post by Richard Smith
Post by Brian Bi
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi
It concerns the following code. The question is whether there's a rule
in the standard that implies that the S&& overload shall be selected over
the const S& overload.
#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&) { std::puts("S&&"); }int main() {
f(42);}
It doesn't seem to have received a response there. I also looked
through the CWG issue list by section, and couldn't find anything relevant
there. Am I just missing something?
http://eel.is/c++draft/over.ics.rank#3.2.3 orders the second standard
conversion sequences of the user-defined conversion sequences here.
http://eel.is/c++draft/over.ics.rank#3.3 orders the user-defined
conversion sequences based on the order of the second standard conversion
sequences.
http://eel.is/c++draft/over.ics.ref#2 appears to imply that in both of
the user-defined conversion sequences, the second standard conversion is
the identity conversion.
I think that's true but irrelevant. /3.2.3 is not dependent on whether the
standard conversion sequences have different categories. Consider this
void f();
int g(void (&)()); // #1
void g(void (&&)()); // #2
int v = g(f);
Here, this calls #1, because the standard conversion sequence for #1 is
better than that for #2, by [over.ics.rank]/3.2.4. And that happens even
though the standard conversion sequence is an identity conversion for the
argument in both cases.
I see---you're saying that in my example, the second standard conversion
sequence actually performs the reference binding, so [over.ics.rank]/3.2.3
applies. I think that this is not clear enough in the standards text---my
reading of [over.ics.ref]/2 had been that the reference binding actually
occurs as part of the user-defined conversion, which would make
[over.ics.rank]/3.2.3 not apply. Do you think it would be appropriate to
open an editorial issue to clarify this in [over.ics.ref]/2?

When a parameter of reference type is not bound directly to an argument
Post by Richard Smith
expression, the conversion sequence is the one required to convert the
argument expression to the referenced type according to 16.3.3.1. In the
case of a user-defined conversion sequence, the binding of the reference to
the result of the user-defined conversion shall be considered to be
performed by the second standard conversion sequence. Conceptually, this
conversion sequence corresponds to copy-initializing a temporary of the
referenced type with the argument expression. Any difference in top-level
cv-qualification is subsumed by the initialization itself and does not
constitute a conversion.
--
*Brian Bi*
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Richard Smith
2018-11-21 05:27:37 UTC
Permalink
Post by Brian Bi
Post by Richard Smith
Post by Richard Smith
Post by Richard Smith
Post by Brian Bi
https://stackoverflow.com/questions/53198515/overload-resolution-between-lvalue-and-rvalue-reference-parameter-when-user-defi
It concerns the following code. The question is whether there's a rule
in the standard that implies that the S&& overload shall be selected over
the const S& overload.
#include <cstdio>struct S {
S(int) {}};void f(const S&) { std::puts("const S&"); }void f(S&&) { std::puts("S&&"); }int main() {
f(42);}
It doesn't seem to have received a response there. I also looked
through the CWG issue list by section, and couldn't find anything relevant
there. Am I just missing something?
http://eel.is/c++draft/over.ics.rank#3.2.3 orders the second standard
conversion sequences of the user-defined conversion sequences here.
http://eel.is/c++draft/over.ics.rank#3.3 orders the user-defined
conversion sequences based on the order of the second standard conversion
sequences.
http://eel.is/c++draft/over.ics.ref#2 appears to imply that in both of
the user-defined conversion sequences, the second standard conversion is
the identity conversion.
I think that's true but irrelevant. /3.2.3 is not dependent on whether
the standard conversion sequences have different categories. Consider this
void f();
int g(void (&)()); // #1
void g(void (&&)()); // #2
int v = g(f);
Here, this calls #1, because the standard conversion sequence for #1 is
better than that for #2, by [over.ics.rank]/3.2.4. And that happens even
though the standard conversion sequence is an identity conversion for the
argument in both cases.
I see---you're saying that in my example, the second standard conversion
sequence actually performs the reference binding, so [over.ics.rank]/3.2.3
applies. I think that this is not clear enough in the standards text---my
reading of [over.ics.ref]/2 had been that the reference binding actually
occurs as part of the user-defined conversion, which would make
[over.ics.rank]/3.2.3 not apply. Do you think it would be appropriate to
open an editorial issue to clarify this in [over.ics.ref]/2?
When a parameter of reference type is not bound directly to an argument
Post by Richard Smith
expression, the conversion sequence is the one required to convert the
argument expression to the referenced type according to 16.3.3.1. In the
case of a user-defined conversion sequence, the binding of the reference to
the result of the user-defined conversion shall be considered to be
performed by the second standard conversion sequence. Conceptually, this
conversion sequence corresponds to copy-initializing a temporary of the
referenced type with the argument expression. Any difference in top-level
cv-qualification is subsumed by the initialization itself and does not
constitute a conversion.
Yes, please open an editorial issue. I'm not sure the above is quite what
we want as a fix (for a start, we need to cover the /1 case too); perhaps
changing [over.ics.rank]/3.2.3 (and /3.2.4 and /3.2.6) to stop pretending
that "reference binding" is a property of an SCS would be better:

"S1 and S2 <del>are</del> <ins>occur within</ins> reference bindings and
neither refers to an implicit object parameter [...]"

Either that, or we should actually say somewhere that reference binding is
something that an SCS can do; then it should be clear that the second
standard conversion sequence of an implicit conversion sequence is where
the reference binding (if any) must happen.
--
---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussion+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.
Continue reading on narkive:
Loading...