diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-03-02 17:14:33 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-03-02 17:14:33 +0100 |
commit | 9e6c2369a177f2df16b046d7342fae8b26511bbb (patch) | |
tree | 7acedb5e3f92ffd229857b644407e4da05a29e73 /compilerplugins | |
parent | 92bface85dc413fc015fd651c538f580ae2da151 (diff) |
plugin:literaltoboolconversion: Recurse into comma operator's rhs
...inspired by <http://www.viva64.com/en/b/0308/#ID0EE4BI>'s V639 finding.
Change-Id: I3b49f00dd4a593ed0b94d81398fa89ff64f6c79b
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/literaltoboolconversion.cxx | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/compilerplugins/clang/literaltoboolconversion.cxx b/compilerplugins/clang/literaltoboolconversion.cxx index 07a7e5084fa0..caae89bc778f 100644 --- a/compilerplugins/clang/literaltoboolconversion.cxx +++ b/compilerplugins/clang/literaltoboolconversion.cxx @@ -43,6 +43,15 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( return true; } Expr const * sub = expr->getSubExpr()->IgnoreParenCasts(); + Expr const * expr2; + for (;;) { + BinaryOperator const * op = dyn_cast<BinaryOperator>(sub); + if (op == nullptr || op->getOpcode() != BO_Comma) { + break; + } + expr2 = op->getRHS()->IgnoreParenCasts(); + sub = expr2; + } if (sub->getType()->isBooleanType()) { return true; } @@ -113,9 +122,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( report( DiagnosticsEngine::Warning, "implicit conversion (%0) of literal of type %1 to %2", - expr->getLocStart()) + expr2->getLocStart()) << expr->getCastKindName() << expr->getSubExpr()->getType() - << expr->getType() << expr->getSourceRange(); + << expr->getType() << expr2->getSourceRange(); } } else if (sub->isNullPointerConstant( compiler.getASTContext(), Expr::NPC_ValueDependentIsNull) @@ -130,9 +139,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( DiagnosticsEngine::Warning, ("implicit conversion (%0) of null pointer constant of type %1 to" " %2"), - expr->getLocStart()) + expr2->getLocStart()) << expr->getCastKindName() << expr->getSubExpr()->getType() - << expr->getType() << expr->getSourceRange(); + << expr->getType() << expr2->getSourceRange(); } else if (!sub->isValueDependent() && sub->isIntegerConstantExpr(res, compiler.getASTContext())) { @@ -140,9 +149,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( DiagnosticsEngine::Warning, ("implicit conversion (%0) of integer constant expression of type" " %1 with value %2 to %3"), - expr->getLocStart()) + expr2->getLocStart()) << expr->getCastKindName() << expr->getSubExpr()->getType() - << res.toString(10) << expr->getType() << expr->getSourceRange(); + << res.toString(10) << expr->getType() << expr2->getSourceRange(); } return true; } |