St.Antario
St.Antario

Reputation: 27455

Understanding lvalue concept

I've read about lvalue concept in c++ 14 N3797 working draft and I have a question about it. The Standard says:

sec. 3.10/1 N3797:

Expressions are categorized according to the taxonomy in Figure 1.

—An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment expression) designates a function or an object. [Example: If E is an expression of pointer type, then *E is an lvalue expression referring to the object or function to which E points. As another example, the result of calling a function whose return type is an lvalue reference is an lvalue. —end example]

It's ok at first glance. But the sec. 5/1 N3797 provides a definition of the expression. It says:

An expression is a sequence of operators and operands that specifies a computation

Now consider sec. 5.4/1:

The result of the expression (T)cast-expression is of type T. The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type and an xvalue if T is an rvalue reference to object type; otherwise the result is a prvalue.

We have that lvalue is an expression by definition (I.e. sequence of operators and operands), and the result of an lvalue is an lvalue (also a sequnce of operators and operands). It is not clear for me how an expression can return an expression after evaluation (lvalue returns lvalue in the quote from 5.4/1 that I cited).

Could you possibly explain it?

Upvotes: 0

Views: 104

Answers (1)

Keith Thompson
Keith Thompson

Reputation: 263627

I think it's just slightly sloppy wording.

In C++ (as well as in C), an "lvalue" is a kind of expression. Rather than

The result is an lvalue if T is an lvalue ...

it should say:

The expression is an lvalue if T is an lvalue ...

The meaning of the word "lvalue" has varied over the years and from one language to another. If I recall correctly, the original idea was that an "lvalue" was a kind of value, and an expression could be evaluated either for its lvalue (determining what object it designates) or for its rvalue (determining a value). Perhaps the author(s) had that meaning in mind when writing that sentence.

Upvotes: 1

Related Questions