Suppose I have the following function:
void foo(std::vector<int> vec, int n);
If I call the function like this:
std::vector<int> numbers { 2, 3, 5, 7, 11, 13, 17, 19 };
foo(std::move(numbers), numbers[0]);
Are all the arguments completely evaluated before being bound to their parameters? In that case, the std::move is harmless, because it simply yields an xvalue referring to numbers. Or can each individual argument immediately be bound to its parameter as soon as it is evaluated? In that case, numbers[0] could cause undefined behavior, because numbers could already have been moved into vec.
On §1.9/15 we’re told that:
And on §5.2.2/4:
I couldn’t find any other relevant text in the final draft. Since this does not explicitly define a sequenced before relationship between evaluation of arguments and the initialization of the parameters, they’re unsequenced and the
std::moveis not harmless.A solution to this issue would be to force a sequence with a temporary variable: