AutosarC++18_03-A18.9.3ΒΆ

The std::move shall not be used on objects declared const or const&

Required inputs: IR

Rationale

If an object is declared const or const&, then it will actually never be moved using the std::move.

Example
// $Id: A18-9-3.cpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#include <utility>
class A {
  // Implementation
};
void F1() {
  const A a1{};
  A a2 = a1;            // Compliant - copy constructor is called
  A a3 = std::move(a1); // Non-compliant - copy constructor is called
                        // implicitly instead of move constructor
}
See Also
  • HIC++ v4.0 [8]: 17.3.1 Do not use std::move on objects declared with const or const& type.

Possible Messages

Key

Text

Severity

Disabled

std_move_const

Call to std::move with argument declared const/const&.

None

False

Options