Code that is executed but does not perform any action, or has an unintended effect, most likely results from a coding error and can cause unexpected behavior. Statements or expressions that have no effect should be identified and removed from code. Most modern compilers can warn about code that has no effect in many cases. (See MSC00-C. Compile cleanly at high warning levels.)
This recommendation is related to MSC07-C. Detect and remove dead code.
Noncompliant Code Example (Assignment)
...
If the intent was to increment the value referred to by p
, then parentheses can be used to ensure p
is dereferenced and then incremented. (See EXP00-C. Use parentheses for precedence of operation.)
Code Block | ||||
---|---|---|---|---|
| ||||
int *p; /* ... */ (*p)++; |
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
| NO_EFFECT | Finds statements or expressions that do not accomplish anything or statements that perform an unintended action. | |||||||
GCC | 3.0 | Options detect unused local variables or nonconstant static variables and unused function parameters, respectively. | |||||||
| EFFECT |
| |||||||
| 65 D | Fully implemented. | |||||||
Splint |
|
|
| ||||||
PRQA QA·CQA-C |
| Partially implemented |
...
CERT C++ Secure Coding Standard: MSC12-CPP. Detect and remove code that has no effect
ISO/IEC TR 24772 "BRS Leveraging human experience," "BVQ Unspecified functionality," "KOA Likely incorrect expressions," and "XYQ Dead and deactivated code"
MISRA Rule 14.1 and Rule 14.2
Sources
...