This is the mail archive of the
mailing list for the GCC project.
Re: value not set via reference
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Conrad S <conradsand dot arma at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Fri, 30 Jan 2015 09:25:51 +0000
- Subject: Re: value not set via reference
- Authentication-results: sourceware.org; auth=none
- References: <CAONgOD78zQFEZf2h9O97tGL9t5XW4FpzYa9atbS8EL1SL4Nz4w at mail dot gmail dot com> <CAKNGpgrc3+Z2bQs5C+5K6KChnUBiPCKU1frvHFVGFbEV=JpGsw at mail dot gmail dot com> <CAONgOD4ismfKDOyOAgSiEH5Bk3fRQqEWtJ2iYO0ynAUtajfPzA at mail dot gmail dot com>
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
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.