AUTOSAR C++14 Rule A5-0-1
The value of an expression shall be the same under any order of evaluation that the standard permits
Description
Rule Definition
The value of an expression shall be the same under any order of evaluation that the standard permits.
Rationale
If an expression results in different values depending on the order of evaluation, its value becomes implementation-defined.
Polyspace Implementation
Polyspace® raises a violation if an expression satisfies any of these conditions:
The same variable is modified more than once in the expression or it is both read and written.
The expression allows more than one order of evaluation which might lead to different results.
The expression contains a single
volatile
object that occurs multiple times.The expression contains more than one
volatile
object.
Because volatile
objects can change their value at
anytime, an expression containing multiple volatile
variables or
multiple instances of the same volatile
variable might have
different results depending on the order of evaluation.
When checking an expression containing function calls, Polyspace checks the body of the functions. If the function body contains calls to other functions, their bodies are not checked. For instance:
int f1(){return 1;} int f2(){return g();} int g(){return 2;} void foo(void){ int z = f1()+f2(); }
z = f1()+f2()
, Polyspace checks the body of f1()
and
f2()
. The body of g()
is not checked.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: Required, Automated |