implicitboolconversion: warn about mixing bool with integer

...in &=, |=, ^=, as does MSVC, too.

Change-Id: I57ecc9d784dd483e04ae561c62595b1d0380517f
This commit is contained in:
Stephan Bergmann
2014-01-25 22:08:14 +01:00
parent 3b4b4ed3b3
commit cd20baf40a

View File

@@ -405,6 +405,16 @@ bool ImplicitBoolConversion::TraverseBinAndAssign(CompoundAssignOperator * expr)
}
}
nested.pop();
if (!ignoreLocation(expr) && isBool(expr->getLHS(), false)
&& !isBool(expr->getRHS()->IgnoreParenImpCasts(), false))
{
report(
DiagnosticsEngine::Warning, "mix of %0 and %1 in operator &=",
expr->getRHS()->getLocStart())
<< expr->getLHS()->getType()
<< expr->getRHS()->IgnoreParenImpCasts()->getType()
<< expr->getSourceRange();
}
return ret;
}
@@ -421,6 +431,16 @@ bool ImplicitBoolConversion::TraverseBinOrAssign(CompoundAssignOperator * expr)
}
}
nested.pop();
if (!ignoreLocation(expr) && isBool(expr->getLHS(), false)
&& !isBool(expr->getRHS()->IgnoreParenImpCasts(), false))
{
report(
DiagnosticsEngine::Warning, "mix of %0 and %1 in operator |=",
expr->getRHS()->getLocStart())
<< expr->getLHS()->getType()
<< expr->getRHS()->IgnoreParenImpCasts()->getType()
<< expr->getSourceRange();
}
return ret;
}
@@ -437,6 +457,16 @@ bool ImplicitBoolConversion::TraverseBinXorAssign(CompoundAssignOperator * expr)
}
}
nested.pop();
if (!ignoreLocation(expr) && isBool(expr->getLHS(), false)
&& !isBool(expr->getRHS()->IgnoreParenImpCasts(), false))
{
report(
DiagnosticsEngine::Warning, "mix of %0 and %1 in operator ^=",
expr->getRHS()->getLocStart())
<< expr->getLHS()->getType()
<< expr->getRHS()->IgnoreParenImpCasts()->getType()
<< expr->getSourceRange();
}
return ret;
}