diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-01-25 22:08:14 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-01-26 12:28:09 +0100 |
commit | cd20baf40aba2153091eb5e7c680fd7e458c3286 (patch) | |
tree | c1f1f66e415de8fbba566cb33391073ef2740740 /compilerplugins/clang/implicitboolconversion.cxx | |
parent | 3b4b4ed3b3fa73265b2f2506985dec6a4e1068f2 (diff) |
implicitboolconversion: warn about mixing bool with integer
...in &=, |=, ^=, as does MSVC, too.
Change-Id: I57ecc9d784dd483e04ae561c62595b1d0380517f
Diffstat (limited to 'compilerplugins/clang/implicitboolconversion.cxx')
-rw-r--r-- | compilerplugins/clang/implicitboolconversion.cxx | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx index 65db49650135..a804b0d1d70e 100644 --- a/compilerplugins/clang/implicitboolconversion.cxx +++ b/compilerplugins/clang/implicitboolconversion.cxx @@ -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; } |