MISRA C++:2008 Rule 6-4-4
A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement
Description
Rule Definition
A switch-label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.1
Rationale
Placing a case-label or default-label of a switch statement in different scopes might result in unstructured code. Unstructured code might lead to unexpected behavior resulting in developer confusion. To prevent this issue, all case-labels and the default-label must be at the same scope of the compound statement forming the body of the switch statement.
Polyspace Implementation
Polyspace® raises this defect whenever a case-label belongs to any scope other than the switch statement body.
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Statements |
Category: Required |
Version History
Introduced in R2013b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.