AUTOSAR C++14 Rule A13-2-2
A binary arithmetic operator and a bitwise operator shall return a "prvalue"
Since R2021a
Description
Rule Definition
A binary arithmetic operator and a bitwise operator shall return a "prvalue".
Rationale
Binary arithmetic operators such as operator+() and bitwise operators
such as operator|() must return an object of type T by
value without qualifiers (and not references, T&, or pointers
,T*). This requirement makes the return types consistent with the
implementation of the same operators in the C++ Standard Library. A developer familiar with
the standard operators can easily work with the overloaded forms of the operators.
A prvalue or pure rvalue is an object that does not have a name, cannot be pointed to or referenced, but can still be moved from. For instance, the result of a call to a function that returns by value is a prvalue.
Polyspace Implementation
The checker flags implementations of binary and bitwise operators that return:
A type with a qualifier such as
constorvolatile.A pointer or reference to another type.
Operators flagged by the checker include:
Binary operators such as
operator+(),operator*(),operator/(), and so on.Bitwise operators such as
operator&(),operator|(),operator<<(), and so on.Note that the checker does not show violations on
operator<<()andoperator>>()that returnstd::basic_istream,std::basic_ostream, orstd::basic_iostreamtypes.
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: Overloading |
| Category: Required, Automated |
Version History
Introduced in R2021a