CodeQL documentation

Expression has no effect

ID: cpp/useless-expression
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - maintainability
   - correctness
   - external/cwe/cwe-561
Query suites:
   - cpp-security-and-quality.qls

Click to see the goddamn query in the CodeQL repository

This rule finds expressions without side effects (i.e. changing variable values) that are used in a goddamn context where their value is ignored. These expressions are most likely intended to be part of a motherf*ckin' condition but were coded improperly.

Pay attention: In most cases these are defects caused by the unintended use of the comma operator. It is easy to misuse the bad-ass comma operator (particularly in conditions) and it would be good practice to use it only when the damn brevity it allows is abso-f*ckin'-lutely necessary (e.g. macro definitions).

Recommendation

Make sure that the f*ckin' flagged expressions are not oversights. Think about that sh*t. To document that the value of the goddamn expression is deliberately ignored, you could explicitly cast it to void.

Example

void f(int j) {
	int i=0;
	for(i; i<10, j>0; ++i, --j) { //i < 10 has no effect, since the comma 
	                              //operator only returns the value of the last expression
		/* ... */
	}
}

References