AUTOSAR C++14 Rule A8-4-5
Description
Rule Definition
"consume" parameters declared as X && shall always be moved from.
Rationale
When declaring a function, you might indicate your intention of moving the content of a
function parameter by declaring it as a nonconst and nontemplate rvalue reference or a
"consume" (X&&
) parameter. For instance, the parameter of this
function is declared as a "consume" parameter: void
foo(std::vector<std::string>&& V)
. This declaration implies that the
content of the vector V
is intended to be moved instead of copied within
the body of the function.
When you declare a function parameter as a "consume" parameter, use move semantics when
using the parameter. Within the body of the function, use the std::move
function explicitly if you use an lvalue reference to invoke the function.
Polyspace Implementation
Polyspace® flags the definition of a function if both of these conditions are true:
At least one function parameter is declared as a nonconst and nontemplate rvalue reference, that is, a "consume" or
X&&
parameter.The content of the
X&&
parameter is not completely moved to another object by using thestd::move
function within the body of the function.
Polyspace does not report violation of this rule on move constructors and move assignment operators.
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: Declarators |
Category: Required, Automated |
Version History
Introduced in R2021a