In the following code:
A & getDataA() ;
B & getDataB() ;
void foo()
{
getDataA() = getDataB() ;
}
Is getDataA()
guaranteed to be evaluated before or after getDataB()
, or is the evaluation of both operands unsequenced one in relation to the other?
Note: I am interested by answers quoting the standard.
.
P.S.: My research so far...
I tried to understand the standard to find the answer, and here is the result of my research. My understanding is that the evaluation of the two operands are unsequenced.
But... (every quote comes from C++14 draft n3797, 5.17 [expr.ass]):
The assignment operator (=) and the compound assignment operators all group right-to-left.
This means that the expression a = b = c ;
is really a = (b = c) ;
.
In all cases, the assignment is sequenced after the value computation of the right and left operands, and before the value computation of the assignment expression.
The first part says that for a = b ;
, the actual assignment will happen after a
and b
are evaluated. The second part baffles me: I can understand it for operator +=
(or another compound assignment operator), but I can't for operator =
.
Looking a the begining of the chapter (5 Expression [expr]), I read:
Uses of overloaded operators are transformed into function calls as described in 13.5. Overloaded operators obey the rules for syntax specified in Clause 5, but the requirements of operand type, value category, and evaluation order are replaced by the rules for function call.
This is what makes me believe the evaluations of the two operands are unsequenced (evaluations of function parameters are unsequenced, unless I missed something) for the cases where A
or B
are not built-ins.
But in the case above, A
and B
could be int
, so the built-in operator =
would be called, not a function.