MISRAC++2008-0-1-2_c
In this section:
Synopsis
(Required) A project shall not contain infeasible paths.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A case statement within a switch statement is unreachable. This check is identical to RED-case-reach, MISRAC2012-Rule-2.1_a, MISRAC++2023-0.0.2_c.
Coding standards
- CERT MSC07-C
Detect and remove dead code
- MISRA C:2012 Rule-2.1
(Required) A project shall not contain unreachable code
- MISRA C++ 2023 0.0.2
(Advisory) Controlling expressions should not be invariant
Code examples
The following code example fails the check and will give a warning:
void example(void) {
int x = 42;
switch(2 * x) {
case 42 : //unreachable case, as x is 84
;
default :
;
}
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
int x = 42;
switch(2 * x) {
case 84 :
;
default :
;
}
}