Implicit conversion to boolean expression

An expression of type int, float or complex is used where a boolean expression is expected. Example:

bool b = z  ; z is a complex variable

or

if (3)

The expression is automatically converted to a boolean expression by comparing it with zero:

bool b = (z != 0)

and

if (3 != 0)

Often this warning indicates logical errors, like confusing the == and = operators. Example:

if (z = 3)

Here z is assigned the value 3, and then 3 is converted to a boolean expression (true) and the statements right after the if statement are always executed. But it is more likely this was the intent:

if (z == 3)

Now the statements after the if statement are only executed when z equals 3.

See Also
Warnings