Miscellaneous-RedundantEnumDefaultClause¶
The “default” clause of a switch must be omitted if a switch has cases for all enumerators
Required inputs: IR
default clause in a switch that has a case for
all enumerators. This is almost in contrast to the rule
MisraC++-6.4.6 that demands a default case --
unless a switch has a case for all enumerators.
Example
enum Colours { RED, BLUE, GREEN } colour;
switch ( colour )
{
case RED:
break;
case BLUE:
break;
case GREEN:
break;
default: // Non-Compliant, though compliant (and defensive) for MisraC++-6.4.6
break;
}
switch ( colour )
{
case RED:
break;
case BLUE:
break;
case GREEN: // Compliant even for MisraC++-6.4.6 (as exception)
break;
}
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
redundant_default |
Switch over complete enum has redundant “default” clause. |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.