MISRA C++:2008 Rule 6-4-3

A switch statement shall be a well-formed switch statement

Description

Rule Definition

A switch statement shall be a well-formed switch statement.

Polyspace Implementation

The checker flags these situations:

  • A statement occurs between the switch statement and the first case statement.

    For instance:

    switch(ch) {
      int temp;
      case 1:
        break;
      default:
        break;
    }

  • A label or a jump statement such as goto or return occurs in the switch block.

  • A variable is declared in a case statement (outside any block).

    For instance:

    switch(ch) {
      case 1: 
        int temp;
        break;
      default:
        break;
    }

Troubleshooting

If you expect a rule violation but do not see it, refer to the documentation for Polyspace® Code Prover™ or Polyspace Code Prover Server™.

Check Information

Group: Statements
Category: Required
Introduced in R2013b