AUTOSAR C++14 Rule A8-4-6
Description
Rule Definition
"forward" parameters declared as T && shall always be forwarded.
Rationale
Because rvalue references cannot bind to lvalues, functions that enable the use of move
semantics by using rvalue references in their signature do not accept lvalues. This issue is
resolved by using an rvalue reference to a nonconst template type object, which is called a
"forward" parameter. These parameters can bind to both rvalues and lvalues while preserving
their cv qualifications and value categories. "Forward" parameters are useful when you want
to forward a value to a destination object or function by using the function
std::forward
.
When you declare a function template by using a "Forward" parameter, do not use the
parameter in any operations. Because "Forward" parameters can bind to both lvalues and
rvalues, using them in an operation might corrupt their cv qualifications and value
categories. Forward these parameters directly to the destination by using
std::forward
without using them in an operation.
Polyspace Implementation
Polyspace® flags a "Forward" parameter in the definition of a function template or a Lambda expression if any of these conditions are true:
A "Forward" parameter is not forwarded to a destination by using
std::forward
.An operation other than forwarding is performed on the "Forward" parameter or on a member object of it.
Polyspace ignores the templates and Lambda expressions that remain unused in your code.
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