Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.SWITCH.LABEL

A switch label belongs to nested compound statement inside switch body.

MISRA-C Rule 15.1 (required): A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.

The scope of a case or default label shall be the compound statement, which is the body of a switch statement. All case clauses and the default clause shall be at the same scope.

MISRA-C++ Rule 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.

Rationale

A switch-label can be placed anywhere within the statements that form the body of a switch statement, potentially leading to unstructured code. To prevent this from happening, the scope of a case-label or default-label shall be the compound statement forming the body of a switch statement. All case-clauses and the default-clause shall be at the same scope.

Example

switch ( x )
{
case 1:          // Compliant
   if ( ... )
   {
   case 2:       // Non-compliant
      DoIt ( );
   }
   break;
default:
   break;
}