MISRAC2004-15.2
Synopsis
(Required) An unconditional break statement shall terminate every non-empty switch clause.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Non-empty switch cases were found that are not terminated by a break statement. This check is identical to MISRAC++2008-6-4-5, MISRAC2012-Rule-16.3, MISRAC++2023-9.4.2_b.
Coding standards
- CERT MSC17-C
Finish every set of statements associated with a case label with a break statement
- CWE 484
Omitted Break Statement in Switch
- MISRA C:2012 Rule-16.3
(Required) An unconditional break statement shall terminate every switch-clause
- MISRA C++ 2008 6-4-5
(Required) An unconditional throw or break statement shall terminate every non-empty switch-clause.
- 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(int input) {
switch(input) {
case 0:
if (rand()) {
break;
}
default:
break;
}
}
The following code example passes the check and will not give a warning about this issue:
void example(int input) {
switch(input) {
case 0:
if (rand()) {
break;
}
break;
default:
break;
}
}