MISRAC2012-Rule-13.4_a
In this section:
Synopsis
(Advisory) The result of an assignment operator should not be used
Enabled by default
No
Severity/Certainty
Low/High

Full description
An assignment might be mistakenly used as the condition for an if, for, while, or do statement. This check is identical to EXP-cond-assign.
Coding standards
- CERT EXP18-C
Do not perform assignments in selection statements
- CERT EXP19-CPP
Do not perform assignments in conditional expressions
- CWE 481
Assigning instead of Comparing
- MISRA C:2012 Rule-13.4
(Advisory) The result of an assignment operator should not be used
Code examples
The following code example fails the check and will give a warning:
int example(void) {
int x = 2;
if (x = 3)
return 1;
return 0;
}
The following code example passes the check and will not give a warning about this issue:
int example(void) {
int x = 2;
if (x == 3)
return 1;
return 0;
}