MISRAC2004-15.1
Synopsis
(Required) A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
Switch labels were found in nested blocks. This check is identical to MISRAC++2008-6-4-4, MISRAC2012-Rule-16.2, MISRAC++2023-9.4.2_f.
Coding standards
- MISRA C:2012 Rule-16.2
(Required) A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
- MISRA C++ 2008 6-4-4
(Required) A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.
- MISRA C++ 2023 9.4.2
(Required) The structure of a switch statement shall be appropriate
Code examples
The following code example fails the check and will give a warning:
void example(void) {
switch(rand()) {
{case 1:}
case 2:
case 3:
default:
}
}
The following code example passes the check and will not give a warning about this issue:
void example(void) {
switch(rand()) {
case 1:
case 2:
case 3:
default:
}
}