Skip to main content

IAR Embedded Workbench for RX 5.20

RED-no-effect

In this section:
Synopsis

A statement potentially contains no side effects.

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

A statement expression seems to have no side-effects and is redundant. For example, 5 + 6; will add 5 and 6, but will not use the result anywhere. Consequently the statement has no effect on the rest of the application, and should probably be deleted. This check is identical to MISRAC2004-14.2, MISRAC2012-Rule-2.2_a.

Coding standards
CERT MSC12-C

Detect and remove code that has no effect

CWE 482

Comparing instead of Assigning

MISRA C:2004 14.2

(Required) All non-null statements shall either have at least one side effect however executed, or cause control flow to change.

MISRA C:2012 Rule-2.2

(Required) There shall be no dead code

Code examples

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

void example(void) {
  int x = 1;
  x = 2;
  x < x;
}

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

#include <string>

void f();
template<class T>
struct X {
  int x;
  
  int get() const {
    return x;
  }
  
  X(int y) :
    x(y) {}  
};

typedef X<int> intX;

void example(void) {
  /* everything below has a side-effect */
  int i=0;
  f();
  (void)f();
  ++i;
  i+=1;
  i++;
  char *p = "test";
  std::string s;
  s.assign(p);
  std::string *ps = &s;
  ps -> assign(p);
  intX xx(1);
  xx.get(); 
  intX(1);
}