Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2023-9.4.2_d

In this section:
Synopsis

(Required) The structure of a switch statement shall be appropriate

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

One or more switch statements without a case clause were found. This check is identical to MISRAC++2008-6-4-8, MISRAC2004-15.5.

Coding standards
MISRA C:2004 15.5

(Required) Every switch statement shall have at least one case clause.

MISRA C++ 2008 6-4-8

(Required) Every switch statement shall have at least one case-clause.

Code examples

The following code example fails the check and will give a warning:

int example(int x) {
  switch(x){
    default:
      return 2;
      break;
  }
}

The following code example passes the check and will not give a warning about this issue:

int example(int x) {
  switch(x){
    case 3:
      return 0;
      break;
    case 5:
      return 1;
      break;
    default:
      return 2;
      break;
  }
}