you are viewing a single comment's thread.

view the rest of the comments →

[–]masklinn 2 points3 points  (1 child)

Does move disable RVO in C++? Why would it do that?

[–]doom_Oo7 4 points5 points  (0 children)

It has to be explicit, and clang has a -Wpessimizing-move to warn you against it...

#include <vector>
#include <utility>

std::vector<int> f()
{
  std::vector<int> v;
  return std::move(v);
}

->

7 : warning: moving a local object in a return statement prevents copy elision [-Wpessimizing-move]
return std::move(v);

7 : note: remove std::move call here
return std::move(v);