Topic: Defect Report: new sequencing rules
Author: oporat@yahoo.com (Ofer Porat)
Date: Sat, 2 Jun 2007 23:42:12 GMT Raw View
In "1.9.16 [intro.execution]" of N2284, the following
expression
is still listed as an example of undefined behavior:
i = ++i + 1;
However, it appears that the new sequencing rules make
this
expression well-defined:
a) The assignment side-effect is required to be
sequenced after
the value computations of both its LHS & RHS (5.17.1.)
b) The LHS (i) is an lvalue, so its value computation
involves
computing the address of i.
c) In order to value-compute the RHS (++i + 1), it is
necessary
to first value-compute the lvalue expression "++i" and
then
do an lvalue-to-rvalue conversion on the result. This
guarantees
that the incrementation side-effect is sequenced
before the
computation of the addition operation, which in turn
is sequenced
before the assignment side effect. In other words, it
yields
a well-defined order and final value for this
expression.
It should be noted that a similar expression
i = i++ + 1;
is still not well-defined, since the incrementation
side-effect
remains unsequenced with respect to the assignment
side-effect.
It's unclear whether making the expression in the
example well-defined
was intentional or just a coincidental byproduct of
the new
sequencing rules. In either case either the example
should be fixed,
or the rules should be changed.
Ofer Porat
oporat@yahoo.com
____________________________________________________________________________________
Get your own web address.
Have a HUGE year through Yahoo! Small Business.
http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]