AutosarC++17_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 271687 2017-03-23 08:57:35Z piotr.tanski $
#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