This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ order of evaluation of operands, arguments
- From: Martin Sebor <msebor at gmail dot com>
- To: Andrew Haley <aph at redhat dot com>, gcc at gcc dot gnu dot org
- Date: Wed, 25 Nov 2015 15:18:36 -0700
- Subject: Re: C++ order of evaluation of operands, arguments
- Authentication-results: sourceware.org; auth=none
- References: <56539AD0 dot 80905 at redhat dot com> <56543423 dot 2010707 at redhat dot com> <5655FD37 dot 60101 at gmail dot com> <5656029D dot 9030309 at redhat dot com>
On 11/25/2015 11:49 AM, Andrew Haley wrote:
On 11/25/2015 06:25 PM, Martin Sebor wrote:
The motivating example in the paper suggests that many C++
programmers expect a left to right order of evaluation here
due to the commonality of constructs like chains of calls.
Sure, I often see
foo.bar(1).bar(2).bar(3), etc.
but does anyone actually do
foo(1)bar(2)bar(3) ?
That doesn't look syntactically valid to me but I suspect what
you mean might be closer to something like this:
foo(1)(bar(2))(baz(3))
which with the right declarations is just a shorthand for this:
foo(1).operator()(bar(2)).operator()(bar(3));
Having foo(1) evaluate before bar(2) becomes important when
(if) one of the uniform call syntax proposals is adopted. With
that, it will possible to write the expression above like so:
operator()(operator()(foo(1), bar(2)), bar(3));
or more generally for (almost) any member function F:
F (F (foo (1), bar (2)), bar (3));
If C++ were to guarantee an order in which function arguments
were evaluated without also imposing an order on the operand
of the function call expression, uniform calls would be error
prone to use.
Martin