Reading through the Bjarne's CPP book I've encountered such a statement: "Where logically feasible, the result of an operator that takes an lvalue operand is an lvalue denoting that lvalue operand", and I really can't wrap my head around it. These are the examples included with this statement:
void f(int x, int y)
{
int j = x = y; // the value of x=y is the value of x after the assignment
int∗ p = &++x; // p points to x
int∗ q = &(x++); // error : x++ is not an lvalue (it is not the value stored in x)
int∗ p2 = &(x>y?x:y); // address of the int with the larger value
int& r = (x<y)?x:1; // error : 1 is not an lvalue
}
Code itself makes sense to me, but it makes sense from my personal understanding of how these operators work. But I can't really apply the statement here, for example for the first line. OK, =
is an operator which can take both lvalue and rvalue operands (and from my understanding lvalue is implicitly converted to rvalue in this case) , then the result of x = y
is an lvalue denoting y
? If I follow this correctly, then I could write int* j = x = y
, but this would be a compile-time error, as the result of x = y
is clearly an rvalue. So I am really confused here.
Can anyone clarify what is this statement is semantically about and how it relates to the given examples step by step?