implicitboolconversion: warn about mixing bool with integer
...in &=, |=, ^=, as does MSVC, too. Change-Id: I57ecc9d784dd483e04ae561c62595b1d0380517f
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user