Subject: Re: standards/5959: c++ language specification error or compiler error??
To: None <netbsd-bugs@netbsd.org>
From: Daniel S. Riley <dsr@mail.lns.cornell.edu>
List: netbsd-bugs
Date: 08/13/1998 13:17:56
twofsonet@graffiti.com (Andrew Brown) writes:
> an "assignment" usually yields an rvalue (unless you write a c++ class
> that returns a non-const reference from operator=(), which is yet
> another way to make your code confusing :), ie:
The 2 December 1996 Working Paper for the C++ standard (the last
public review draft) section 5.17 [expr.ass] says:
1 There are several assignment operators, all of which group right-to-
left. All require a modifiable lvalue as their left operand, and the
type of an assignment expression is that of its left operand. The
result of the assignment operation is the value stored in the left
operand after the assignment has taken place; the result is an lvalue.
^^^^^^^^^^^^^^^^^^^^^^^
Since the (draft) standard explicitly specifies that the result of the
assignment operator is an lvalue, not only is your example legal, so
is
(foo=3) = 5;
and according to the standard, so is
(foo == 0 ? bar : baz) = 5;
I imagine there is some terribly good reason for all this, but you'd
have to ask on comp.std.c++ to find out what it is.
--
Dan Riley dsr@mail.lns.cornell.edu
Wilson Lab, Cornell University <URL:http://www.lns.cornell.edu/~dsr/>
"History teaches us that days like this are best spent in bed"