Skip to main content

IAR Embedded Workbench for RL78 5.20

MISRAC++2008-0-1-9

In this section:
Synopsis

(Required) There shall be no dead code.

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A part of the application is never executed. This check is identical to RED-dead, MISRAC2004-14.1, MISRAC++2008-0-1-1, MISRAC2012-Rule-2.1_b, MISRAC++2023-0.0.1.

Coding standards
CERT MSC07-C

Detect and remove dead code

CWE 561

Dead Code

MISRA C:2004 14.1

(Required) There shall be no unreachable code.

MISRA C:2012 Rule-2.1

(Required) A project shall not contain unreachable code

MISRA C++ 2008 0-1-1

(Required) A project shall not contain unreachable code.

MISRA C++ 2023 0.0.1

(Required) A function shall not contain unreachable statements

Code examples

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

#include <stdio.h>

int f(int mode) {
    switch (mode) {
        case 0:
            return 1;
            printf("Hello!"); // This line cannot execute.
        default:
            return -1;
    }
}

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

#include <stdio.h>

int f(int mode) {
    switch (mode) {
        case 0:
            printf("Hello!"); // This line can execute.
            return 1;
        default:
            return -1;
    }
}