Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC2012-Rule-2.1_a

In this section:
Synopsis

(Required) A project shall not contain unreachable code.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A case statement within a switch statement cannot be reached. This check is identical to RED-case-reach, MISRAC++2008-0-1-2_c, MISRAC++2023-0.0.2_c.

Coding standards
CERT MSC07-C

Detect and remove dead code

MISRA C:2012 Rule-2.1

(Required) A project shall not contain unreachable code

MISRA C++ 2008 0-1-2

(Required) A project shall not contain infeasible paths.

MISRA C++ 2023 0.0.2

(Advisory) Controlling expressions should not be invariant

Code examples

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

void example(void) {
  int x = 42;

  switch(2 * x) {
  case 42 :  //unreachable case, as x is 84
    ;
  default :
    ;
  }
}

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

void example(void) {
  int x = 42;

  switch(2 * x) {
  case 84 :
    ;
  default :
    ;
  }
}