MISRAC++2023-9.4.2_e (C++ only)
In this section:
Synopsis
(Required) The structure of a switch statement shall be appropriate
Enabled by default
Yes
Severity/Certainty
Medium/High

Full description
A switch statement without default statement or all values of an enumeraton listed.
Coding standards
This check does not correspond to any coding standard rules.
Code examples
The following code example fails the check and will give a warning:
int example(int x) {
switch ( x ) // Non-compliant - no default
{
case 1:
return 1;
case 2:
return 4;
}
}
The following code example passes the check and will not give a warning about this issue:
int example(int x) {
switch ( x )
{
case 1:
return 1;
case 2:
return 4;
default:
return 0;
}
}