AUTOSAR C++14 Rule A13-1-3
User defined literals operators shall only perform conversion of passed parameters
Since R2021a
Description
Rule Definition
User defined literals operators shall only perform conversion of passed parameters.
Rationale
User-defined literal operators are expected to simply convert their parameters to the operator return type. If your operators perform operations other than this conversion, reviewers or other developers who use the operator might find this behavior unexpected.
For instance, the operator _km
is expected to convert a long
long int
parameter to the type
Distance
:
Distance operator"" _km(long long int param) { ... }
Polyspace Implementation
The checker flags user-defined literal operators that have one of these issues:
The operator has a return type
void
. Such an operator cannot return the converted parameter.The operator does not even use its parameter, let alone convert its parameter to the operator return type.
The operator performs an operation that has or might have side-effects. Such an operator defies the expectation that a user-defined literal operator only converts its parameter. For instance, the operator might update a global or static variable (definite side-effect) or call another function (possible side-effect). In the latter case, look into the callee function body to make sure it does not have side effects.
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