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

Four kinds of expression

120 views
Skip to first unread message

Nikolay Ivchenkov

unread,
Jan 4, 2010, 10:09:35 AM1/4/10
to
The following paper
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n3010.pdf
proposes to separate expressions into 3 kinds: rref lvalue, non-rref
lvalue, and rvalue.

I can imagine 4 kinds of an expression:
1) ref lvalue (which is non-rref lvalue in N3010)
2) non-ref lvalue (new kind)
3) ref rvalue (which is rref lvalue in N3010)
4) non-ref rvalue (which is rvalue in N3010).

According to this concept, every expression is either an lvalue or an
rvalue, and every expression is either a ref expression or a non-ref
expression.

-- An rvalue expression designates an entity that shall be treated as
temporary (for example: an enumerator, an object returned by value or
by rvalue reference). Any other expression is an lvalue (for example:
a function, a local variable, an object returned by lvalue reference,
a bit-field).

-- A ref expression is a reference or an addressable expression that
can be converted to a reference type using reinterpret_cast (for
example: a function, a local variable, an object returned by lvalue
reference). Any other expression is a non-ref expression (for example:
enumerator, bit-field, an object returned by value).

Like some rvalues, bit-fields are not addressable. However, bit-fields
can be treated as temporary and as non-temporary:

struct X
{
X() : m(1) {}
int m : 10;
};

template <class T>
void f(T &);
template <class T>
void f(T const &) {}

int main()
{
X x;
f(X().m); // OK: X().m is an rvalue
f(x.m); // ill-formed: X().m is an lvalue
}

This example demonstrates collision between two concepts of lvalue:
designation of an addressable entity and designation of a possibly non-
temporary entity. It seems, the model with 4 kinds of expressions
looks more consistent. For the purposes of the overload resolution non-
ref lvalues could be treated like rvalues.

--
[ 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 ]

0 new messages