Extra Clang Tools 3.9 documentation

clang-tidy - misc-move-const-arg

«  misc-misplaced-widening-cast   ::   Contents   ::   misc-move-constructor-init  »

misc-move-const-arg

The check warns

  • if std::move() is called with a constant argument,
  • if std::move() is called with an argument of a trivially-copyable type, or
  • if the result of std::move() is passed as a const reference argument.

In all three cases, the check will suggest a fix that removes the std::move().

Here are examples of each of the three cases:

const string s;
return std::move(s);  // Warning: std::move of the const variable has no effect

int x;
return std::move(x);  // Warning: std::move of the variable of a trivially-copyable type has no effect

void f(const string &s);
string s;
f(std::move(s));  // Warning: passing result of std::move as a const reference argument; no move will actually happen

«  misc-misplaced-widening-cast   ::   Contents   ::   misc-move-constructor-init  »