Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

C++0x, N2960, rvalue reference issues

7 views
Skip to first unread message

SG

unread,
Nov 12, 2009, 12:24:40 PM11/12/09
to
It seems there are still some places in N2960 where the term "rvalue"
is used without having accounted for rvalue references:


"1.3.4.: The dynamic type [...] [Example: if a pointer p whose static
type is "pointer to class B is pointing to an object of class D,
derived from B, the dynamic type of the expression *p is D. References
are treated similarly. -- end example] The dynamic type of an rvalue
expression is its static type."

So, what's it gonna be? An unnamed rvalue reference is both a
reference and an rvalue expression.


"3.10/2: An lvalue refers to an object or function. Some rvalue
expressions -- those of class or cv-qualified class type -- also refer
to objects."

Doesn't an unnamed rvalue *reference* of type int&& also *refer* to an
object?


"3.10/7: Whenever an lvalue appears in a context where an rvalue
expression is expected, the lvalue is converted to an rvalue."

What are these "contexts"? I would think that "int&& foo = ...;" isn't
one of them, although it is a context where an rvalue expression is
needed according to the not-so-new-anymore reference binding rules.


"3.10/9: [...] Rvalues shall always have complete types or the void
type; in addition to these types, lvalues can also have incomplete
types."

Hmmm... Since "every expression is either an rvalue or an
lvalue" (3.10/1) the above line seems to suggest that there cannot be
unnamed rvalue reference T&& where T is an incomplete type. I don't
think that this is intended.


The overall problem seems to be that we have only two terms --
"lvalue" and "rvalue" -- but actually *three* different kinds of
expressions as far as the rules are concerned:
1. "direct" rvalue expression (no reference)
2. "indirect" rvalue expression (unnamed rvalue reference)
3. lvalue expression

Sometimes "rvalue" is used to denote expressions of class 1 and 2. In
other situations "rvalue" is used to denote expressions of class 1
only.


Cheers,
SG

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]

Johannes Schaub (litb)

unread,
Nov 12, 2009, 1:58:35 PM11/12/09
to
SG wrote:

> It seems there are still some places in N2960 where the term "rvalue"
> is used without having accounted for rvalue references:
>
>
> "1.3.4.: The dynamic type [...] [Example: if a pointer p whose static
> type is "pointer to class B is pointing to an object of class D,
> derived from B, the dynamic type of the expression *p is D. References
> are treated similarly. -- end example] The dynamic type of an rvalue
> expression is its static type."
>
> So, what's it gonna be? An unnamed rvalue reference is both a
> reference and an rvalue expression.
>
>

This is http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#690


> "3.10/7: Whenever an lvalue appears in a context where an rvalue
> expression is expected, the lvalue is converted to an rvalue."
>
> What are these "contexts"? I would think that "int&& foo = ...;" isn't
> one of them, although it is a context where an rvalue expression is
> needed according to the not-so-new-anymore reference binding rules.
>

This is http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#964

SG

unread,
Nov 15, 2009, 8:04:51 PM11/15/09
to
On 12 Nov., 19:58, Johannes Schaub (litb) wrote:
> SG wrote:
> > It seems there are still some places in N2960 where the term "rvalue"
> > is used without having accounted for rvalue references:

[...]

> This is http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#690

[...]

> This is http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#964

Thanks for pointing out the CWG issues. So, 2 out of 4 are already CWG
issues.

It seems N3010 covers a lot of what I was trying to say:
"Rvalue References as Funny Lvalues" by William M. Miller
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3010.pdf

The only difference is that the author splits "lvalue" into two
subcategories (rref lvalue and non-rref lvalue) where I informally
proposed splitting "rvalue" into two subcategories "direct rvalue" and
"indirect rvalue". But in the end that leaves three equivalent
categories:

me | William M. Miller
----------------+------------------
direct rvalue | rvalue
indirect rvalue | rref lvalue
lvalue | non-rref lvalue

I guess both namings are initially somewhat confusing. To be honest, I
find a category named "non-rref lvalue" that includes
_named_rvalue_references_ unfortunate. But William M. Miller and I
seem to agree that instead of two categories (lvalue, rvalue) the use
of three categories is appropriate and avoids some special cases in
the rules.

Cheers,
SG

0 new messages