In this section:

Overview

This error is generated when code is not evaluated, has no effect, or is unreachable. Insure++ distinguishes between several types of dead code:

CodeDescriptionEnabledReportedPlatform
DEAD_CODE

Code is not evaluated, has no effect, or is unreachable

(error)

Compilation

Windows/Unix
(emptyloopbody)Loop body is empty.(error)CompilationWindows/Unix
(emptystmt)The statement is empty.(error)CompilationWindows/Unix
(noeffect)Code has no effect.(error)CompilationWindows/Unix
(notevaluated)Code is not evaluated.(error)CompilationWindows/Unix


Error messages are classified according to this scheme and can be selectively enabled or disabled. By default, this error category is suppressed.

Problem

The following code has several types of DEAD_CODE errors in C.

/*
 * File: deadcode.c
 */
int main()
{
	int i = 0;

	;
	i;
	for (i; i; i)
			;
	return 0;
}

Diagnosis During Compilation

	[deadcode.c:9] **DEAD_CODE(noeffect)**
	Expression has no effect.
>> 		i;
[deadcode.c:10] **DEAD_CODE(noeffect)**
	Expression has no effect.
>> 		for (i; i; i)
	[deadcode.c:10] **DEAD_CODE(noeffect)**
		Expression has no effect.
>> 		for (i; i; i)
  • Line 1: Source line at which the problem was detected.
  • Line 2: Description of the problem and the expression that is incorrect.
  • Line 6: Initializer in for-loop does nothing.
  • Line 9: Increment expression in for-loop does nothing.

Repair

These errors are usually corrected by removing the superfluous statement or by modifying the statement so that it does what it was intended to do, e.g., add a missing increment operator. An empty loop body may be useful in certain situations. In such a case, you may want to suppress that subcategory of DEAD_CODE.

  • No labels