Comparison where assignment was intended¶
This rule finds uses of the equality operator
== in places where the assignment operator
= would make more sense. This is a common mistake in C and C++, because of the similarity of the
= and the
== operator, and the fact that expressions are valid as top-level statements.
The rule flags every occurrence of an equality operator in a position where its result is discarded.
Check to ensure that the flagged expressions are not typos. If the result of an equality test is really intended to be discarded, it should be explicitly cast to
x == 4; // most likely = was intended. Otherwise this statement has no effect.