AUTOSAR C++14 Rule M5-0-2
Limited dependence should be placed on C++ operator precedence rules in expressions
Description
Rule Definition
Limited dependence should be placed on C++ operator precedence rules in expressions.
Rationale
Use parentheses to clearly indicate the order of evaluation.
Depending on operator precedence can cause the following issues:
If you or another code reviewer reviews the code, the intended order of evaluation is not immediately clear.
It is possible that the result of the evaluation does not meet your expectations. For instance:
In the operation
*p++
, it is possible that you expect the dereferenced value to be incremented. However, the pointerp
is incremented before the dereference.In the operation
(x == y | z)
, it is possible that you expectx
to be compared withy | z
. However, the==
operation happens before the|
operation.
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: Expressions |
Category: Advisory, Partially automated |
Version History
Introduced in R2019a