I understand the problems with the classic example of
int i=0;
foo(i++, i++);
but I can’t convince myself of whether the following is valid or invalid
int foo(int& i)
{
i=42;
return 99;
}
bar(foo(i), i);
I understand that the order ‘foo(i)’ and ‘i’ are evaluated is undefined, but what exactly does ‘evaluated’ mean? i.e. will the 2nd parameter of bar always be 42, or can the current value of ‘i’ be passed in before foo changes it?
No it is not guaranteed.
The order of evaluation of arguments to an function is Unspecified[Ref 1].
It can be possible that either:
foo(i)gets evaluated first origets evaluated orUnspecified in this context means the implementation is allowed to implement the said feature whichever way they want and it need not be documented.
[Ref 1]
C++03 5.2.2 Function call
Para 8