C++ order of evaluation of operands, arguments
Martin Sebor
msebor@gmail.com
Tue Nov 24 14:59:00 GMT 2015
On 11/23/2015 04:01 PM, Jason Merrill wrote:
> There's a proposal working through the C++ committee to define the order
> of evaluation of subexpressions that previously had unspecified ordering:
>
> http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2015/p0145r0.pdf
>
> I agree with much of this, but was concerned about the proposal to
> define order of evaluation of function arguments as left-to-right, since
> GCC does right-to-left on PUSH_ARGS_REVERSED targets, including x86_64.
>
> Any thoughts?
I have no comments on the impact on the implementation but I do
have a couple of general concerns with the proposal.
As others have already suggested, I think a change like this needs
to be coordinated with WG14 and made either in both languages or
in neither. If C++ were to make it alone, C++ programmers who only
occasionally write C code would be prone to introducing bugs into
their C code by relying on the C++ guarantees. As WG14 is just
starting to talk about the goals for C2x, this seems like a good
time to bring it up for consideration.
Even in C++, though, I'd worry that specifying the evaluation order
for just a subset of expression would lead to portability bugs
creeping in as programmers inadvertently start to assume that
the same order is guaranteed for all expressions.
Martin
More information about the Gcc
mailing list