On 30 January 2015 at 07:23, Conrad S wrote: > On 30 January 2015 at 16:58, James Dennett wrote: >> It's hardly just a loophole: C++ doesn't specify the order of evaluation, >> so the code is wrong (i.e., non-portable, as you've found). >> >> Arguably this is a design problem with IOStreams, given how >> tempting it can be to write code that assumes left-to-right evaluation, >> but it's not a compiler bug. > > Okay, but what is the reason for changing the "expected" > (left-to-right) order of evaluation? Is there an optimisation > benefit?
Yes. IIUC Clang doesn't always order left-to-right, sometimes it reorders arguments because doing so avoids having to spill a register to memory so that the register can be reused for the evaluation of another argument. So yes, allowing the compiler to decide on the order of evaluation can have significant benefits. > If not, why change the order to something unexpected? There is no "change", you're presupposing a particular order, which is not a valid assumption.