Re: Guarantee of side-effect free assignment
* James Dennett:
Alf P. Steinbach wrote:
I can find no such guarantee in the standard. It
seems the compiler is free to rewrite
p = new S();
as
p = operator new( sizeof( S ) );
new( p ) S();
What would grant the compiler freedom to deviate in such an
observable way from the semantics of the abstract machine (in
which, I hope it is clear, the rhs of an assignment is evaluated
before its result -- if there is one -- is assumed to be known).
Tjat rule is not only not clear, it seems to be non-existent.
Nobody has so far been able to come up with chapter and verse.
That includes me, James Kanze, and a lot of other knowledgable people.
Added to that, in the only Defect Report (slightly) relevant to this
issue, DR 222 [1], Andrew Koenig argued that
"One way to deal with this issue [which is not exactly the above]
would be to include built-in operators in the rule that puts a
sequence point between evaluating a function's arguments and
evaluating the function itself. However, that might be overkill:"
I.e., it might be "overkill" to make all built-in operators act formally
like function calls.
Whether Andrew thought it would also be "overkill" for just assignment
isn't clear, but since DR 222 is mainly about assignment we can conclude
that in his opinion at the time, the standard did not specify complete
evaluation of arguments before assignment effect.
Btw., I totally agree with you as to how this /should/ ideally be! :-)
I think! <g>
Cheers,
- Alf
Notes:
[1] <url: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#222>
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
---
[ 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 ]