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.WELL_FORMED.BREAK.2012

An unconditional break statement shall terminate every switch-clause.

MISRA C 2012 Rule 16.3: An unconditional break statement shall terminate every switch-clause

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Rationale

If a developer fails to end a switch-clause with a break statement, then control fl ow “falls” into the following switch-clause or, if there is no such clause, off the end and into the statement following the switch statement. Whilst falling into a following switch-clause is sometimes intentional, it is often an error. An unterminated switch-clause occurring at the end of a switch statement may fall into any switch-clauses which are added later.

To ensure that such errors can be detected, the last statement in every switch-clause shall be a break statement, or if the switch-clause is a compound statement, the last statement in the compound statement shall be a break statement.

Note: a switch-clause is defined as containing at least one statement. Two consecutive labels, case or default, do not have any intervening statement and are therefore permitted by this rule.

Example

switch ( x ) 
{
  case 0:
    break;                       /* Compliant - unconditional break                */   
  case 1:                        /* Compliant - empty fall through allows a group  */
  case 2:
    break;                       /* Compliant                                      */ 
  case 4:
    a = b;                       /* Non-compliant - break omitted                  */ 
  case 5:
    if ( a == b ) 
    {
       ++a; 
       break;                    /* Non-compliant - conditional break              */ 
    }
  default:
    ;                            /* Non-compliant - default must also have a break  */ 
}

See also

Rule 16.1