summaryrefslogtreecommitdiff
path: root/compilerplugins
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-04-20 16:45:17 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-04-20 17:25:31 +0200
commita3858ed3a785507e7ed9c02cb1e145d2a4c4659b (patch)
tree9a39201f1fca556327aebde1400247a58adf104e /compilerplugins
parent12a4f93d1d412d58b1b13d814de589b10aa41e01 (diff)
Use cast to bool to normalize sal_Bool values
Change-Id: I8a886f752d2a16ec4c10656bcd0b3631647971b2
Diffstat (limited to 'compilerplugins')
-rw-r--r--compilerplugins/clang/implicitboolconversion.cxx13
1 files changed, 13 insertions, 0 deletions
diff --git a/compilerplugins/clang/implicitboolconversion.cxx b/compilerplugins/clang/implicitboolconversion.cxx
index 8aa65434a8c5..9fa073c43fd7 100644
--- a/compilerplugins/clang/implicitboolconversion.cxx
+++ b/compilerplugins/clang/implicitboolconversion.cxx
@@ -110,6 +110,11 @@ bool isMatchingBool(Expr const * expr, Expr const * comparisonExpr) {
|| areSameTypedef(expr->getType(), comparisonExpr->getType());
}
+bool isSalBool(QualType type) {
+ auto t = type->getAs<TypedefType>();
+ return t != nullptr && t->getDecl()->getName() == "sal_Bool";
+}
+
bool isBoolExpr(Expr const * expr) {
if (isBool(expr)) {
return true;
@@ -836,6 +841,14 @@ bool ImplicitBoolConversion::VisitImplicitCastExpr(
== expr->getType().IgnoreParens())
&& isBool(sub->getSubExpr()->IgnoreParenImpCasts()))
{
+ // Ignore "normalizing cast" bool(b) from sal_Bool b to bool, then
+ // implicitly cast back again to sal_Bool:
+ if (dyn_cast<CXXFunctionalCastExpr>(sub) != nullptr
+ && sub->getType()->isBooleanType() && isSalBool(expr->getType())
+ && isSalBool(sub->getSubExpr()->IgnoreParenImpCasts()->getType()))
+ {
+ return true;
+ }
report(
DiagnosticsEngine::Warning,
"explicit conversion (%0) from %1 to %2 implicitly cast back to %3",