MISRAC2012-Rule-2.2_a
In this section:
Synopsis
(Required) There shall be no dead code.
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
A statement potentially contains no side effects. This check is identical to RED-no-effect, MISRAC2004-14.2.
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);
}