Topic: C++11 Ranking implicit conversion sequences (13.3.3.2)
Author: michael@mehlich.com
Date: Sun, 30 Sep 2012 21:17:23 CST
Raw View
The standard (actually earlier versions as well as the current github
draft) provide the following statement in 13.3.3.2 for comparing
conversion sequences:
"Standard conversion sequence S1 is a better conversion sequence than
standard conversion sequence S2 if ...
S1 and S2 are reference bindings (8.5.3) and neither refers to an
implicit object parameter of a non-static member function declared
without a ref-qualifier, and S1 binds an rvalue reference to an
rvalue and S2 binds an lvalue reference."
This is immediately followed by the example:
int g(const int&);
int g(const int&&);
int j = g(i); // calls g(const int &)
which is a preference of binding an lvalue reference to an lvalue over
binding an rvalue reference to an lvalue.
The above statement does not say anything about this preference, nor
could I find any other statement in 13.3.3.2 that would provide this
preference.
Did I miss something somewhere?
What is the correct resolution rule for this?
If it is "prefer binding an lvalue reference to an lvalue over
binding an rvalue reference to an lvalue" then the next statement
in the standard becomes obsolete as it just imposes an additional
restriction to functions...
--
Michael
--- news://freenews.netfront.net/ - complaints: news@netfront.net ---
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?windows-1252?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Tue, 2 Oct 2012 02:57:56 CST
Raw View
On 2012-10-01 05:17, michael@mehlich.com wrote:
>
>
> The standard (actually earlier versions as well as the current github
> draft) provide the following statement in 13.3.3.2 for comparing
> conversion sequences:
>
> "Standard conversion sequence S1 is a better conversion sequence than
> standard conversion sequence S2 if ...
> S1 and S2 are reference bindings (8.5.3) and neither refers to an
> implicit object parameter of a non-static member function declared
> without a ref-qualifier, and S1 binds an rvalue reference to an
> rvalue and S2 binds an lvalue reference."
>
> This is immediately followed by the example:
> int g(const int&);
> int g(const int&&);
> int j = g(i); // calls g(const int &)
> which is a preference of binding an lvalue reference to an lvalue over
> binding an rvalue reference to an lvalue.
>
> The above statement does not say anything about this preference, nor
> could I find any other statement in 13.3.3.2 that would provide this
> preference.
The wording here is indeed broken, as described by core issue
http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1414
but for different reasons as you describe. Note that 13.3.3.2 p3 is
about valid conversion sequences, but binding of an lvalue of T to an
rvalue reference of T is no valid conversion sequence. The key part of
this example is the one that you have left out in your quotation,
namely
int k = g(f1()); // calls g(const int&&)
int l = g(f2()); // calls g(const int&&)
which demonstrates that rvalues are preferrably bound to rvalue
references. The first part about
int j = g(i); // calls g(const int&)
is just given to show how lvalues behave (It is not affected by this
rule). Note that similar examples that are not directly related to the
corresponding rule are also given at other places, like
a << 1; // calls A::operator<<(int)
a << c ; // calls A::operator<<(int)
or
a.p(); // calls A::p()&
> Did I miss something somewhere?
> What is the correct resolution rule for this?
Just strike "to an rvalue" from the current wording.
HTH & Greetings from Bremen,
- Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:std-cpp-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]