MISRAC++2023-0.0.2_b
In this section:
Synopsis
(Advisory) Controlling expressions should not be invariant.
Enabled by default
No
Severity/Certainty
Medium/Medium

Full description
The condition in if, for, while, do-while statement sequences and the ternary operator will never be met. This check is identical to MISRAC++2008-0-1-2_b, MISRAC2012-Rule-14.3_b, RED-cond-never.
Coding standards
- CERT EXP17-C
Do not perform bitwise operations in conditional expressions
- CWE 570
Expression is Always False
- MISRA C:2012 Rule-14.3
(Required) Controlling expressions shall not be invariant
- MISRA C++ 2008 0-1-2
(Required) A project shall not contain infeasible paths.
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int x = 5;
for (x = 0; x < 6 && x >= 1; x++) {
}
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int x = 5;
for (x = 0; x < 6 && x >= 0; x++) {
}
}