https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64870

--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Conrad from comment #6)
> (In reply to Andrew Pinski from comment #5)
> > No, that is not how C++ defines it.  As mentioned before C++ does not define
> > the order of the execution of the operands.
> 
> I agree this is not how C++ defines it. At the same time, changing the order
> from left-to-right "just because we can" is not a good strategy either,
> especially for iostreams.

There is no re-order.  One of the reasons why the order is different is due to
the different ABIs pass arguments.  Some pass them low on the stack to higher,
others opposite way around.  There are two ABIs on x86 that have the opposite
order.

> 
> > There is no wtf moments.  This is not Java which has well defined behavior
> > :).
> 
> Ha :-)  I'd still like to see some concrete benchmarks to support
> re-ordering.  Otherwise it can be argued that the re-ordering is actually
> counter productive, given its unintuitive behaviour.
> 
> Given a choice between gcc and clang, I'd pick clang because it's simply
> better behaved.  This is not to dismiss the great effort put into gcc, but
> user-friendliness is important.

User-friendliness is important but this is not about user-friendliness now.  It
is more about understanding the language that you are writing in.  we have
-Wsequence-point and that normally catches this but with arguments that take
references (or address of variables), it is hard to tell if that function will
change the value or not.

Mis-understanding the language is a common issue and that is why there is even
an FAQ about this exact issue (it has been part of GCC's documentation for at
least 10 years now even).  I also wonder how old
http://c-faq.com/expr/seqpoints.html is too :).

Or better yet:
http://www.stroustrup.com/bs_faq2.html#evaluation-order

Reply via email to