MISRA C++:2023 Rule 28.6.1
Description
Rule Definition
The argument to std::move shall be a
non-const lvalue. 1
Rationale
When arguments to std::move() are specified as
const or const&, the copy constructor is called
instead of the move constructor.
Avoid calling the std::move() function on const
objects. If you want to perform a move operation, cast the const object
to a non-const object, and then move the non-const
object.
Polyspace Implementation
Polyspace® reports a violation of this rule when the std::move()
function is called on any of these objects:
A
constorconst&object.A temporary object. Temporary objects are not lvalues.
A pure rvalue such as a literal value.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Algorithms library |
| Category: Required |
Version History
Introduced in R2024b1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.