Skip to main content

IAR Embedded Workbench for RX 5.20

MISRAC++2008-6-4-5

In this section:
Synopsis

(Required) An unconditional throw or break statement shall terminate every non-empty switch-clause.

Enabled by default

Yes

Severity/Certainty

Medium/Medium

mediummedium.png
Full description

Non-empty switch cases were found that are not terminated by a break. This check is identical to MISRAC2004-15.2, MISRAC2012-Rule-16.3, MISRAC++2023-9.4.2_b.

Coding standards
CERT MSC17-C

Finish every set of statements associated with a case label with a break statement

CWE 484

Omitted Break Statement in Switch

MISRA C:2004 15.2

(Required) An unconditional break statement shall terminate every non-empty switch clause.

MISRA C:2012 Rule-16.3

(Required) An unconditional break statement shall terminate every switch-clause

MISRA C++ 2023 9.4.2

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

Code examples

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

#include <cstdlib>

void example(int input) {

  switch(input) {
    case 0:
      if (rand()) {
        break;
      }
    default:
      break;
  }

}

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

#include <cstdlib>

void example(int input) {

  switch(input) {
    case 0:
      if (rand()) {
        break;
      }
      break;
    default:
      break;
  }

}