Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #549

Re: C++11 Ranking implicit conversion sequences (13.3.3.2)

Message-ID <k4bevl$jfl$1@dont-email.me> (permalink)
Newsgroups comp.std.c++
From Daniel Krügler <daniel.kruegler@googlemail.com>
Subject Re: C++11 Ranking implicit conversion sequences (13.3.3.2)
Organization A noiseless patient Spider
References <k4852m$2bs3$1@adenine.netfront.net>
Date 2012-10-02 02:57 -0600

Show all headers | View raw


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                      ]

Back to comp.std.c++ | Previous | NextPrevious in thread | Find similar


Thread

C++11 Ranking implicit conversion sequences (13.3.3.2) michael@mehlich.com - 2012-09-30 21:17 -0600
  Re: C++11 Ranking implicit conversion sequences (13.3.3.2) Daniel Krügler <daniel.kruegler@googlemail.com> - 2012-10-02 02:57 -0600

csiph-web