Kaydet (Commit) 9e6c2369 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

plugin:literaltoboolconversion: Recurse into comma operator's rhs

...inspired by <http://www.viva64.com/en/b/0308/#ID0EE4BI>'s V639 finding.

Change-Id: I3b49f00dd4a593ed0b94d81398fa89ff64f6c79b
üst 92bface8
...@@ -43,6 +43,15 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -43,6 +43,15 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
return true; return true;
} }
Expr const * sub = expr->getSubExpr()->IgnoreParenCasts(); 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()) { if (sub->getType()->isBooleanType()) {
return true; return true;
} }
...@@ -113,9 +122,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -113,9 +122,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
report( report(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
"implicit conversion (%0) of literal of type %1 to %2", "implicit conversion (%0) of literal of type %1 to %2",
expr->getLocStart()) expr2->getLocStart())
<< expr->getCastKindName() << expr->getSubExpr()->getType() << expr->getCastKindName() << expr->getSubExpr()->getType()
<< expr->getType() << expr->getSourceRange(); << expr->getType() << expr2->getSourceRange();
} }
} else if (sub->isNullPointerConstant( } else if (sub->isNullPointerConstant(
compiler.getASTContext(), Expr::NPC_ValueDependentIsNull) compiler.getASTContext(), Expr::NPC_ValueDependentIsNull)
...@@ -130,9 +139,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -130,9 +139,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
("implicit conversion (%0) of null pointer constant of type %1 to" ("implicit conversion (%0) of null pointer constant of type %1 to"
" %2"), " %2"),
expr->getLocStart()) expr2->getLocStart())
<< expr->getCastKindName() << expr->getSubExpr()->getType() << expr->getCastKindName() << expr->getSubExpr()->getType()
<< expr->getType() << expr->getSourceRange(); << expr->getType() << expr2->getSourceRange();
} else if (!sub->isValueDependent() } else if (!sub->isValueDependent()
&& sub->isIntegerConstantExpr(res, compiler.getASTContext())) && sub->isIntegerConstantExpr(res, compiler.getASTContext()))
{ {
...@@ -140,9 +149,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr( ...@@ -140,9 +149,9 @@ bool LiteralToBoolConversion::VisitImplicitCastExpr(
DiagnosticsEngine::Warning, DiagnosticsEngine::Warning,
("implicit conversion (%0) of integer constant expression of type" ("implicit conversion (%0) of integer constant expression of type"
" %1 with value %2 to %3"), " %1 with value %2 to %3"),
expr->getLocStart()) expr2->getLocStart())
<< expr->getCastKindName() << expr->getSubExpr()->getType() << expr->getCastKindName() << expr->getSubExpr()->getType()
<< res.toString(10) << expr->getType() << expr->getSourceRange(); << res.toString(10) << expr->getType() << expr2->getSourceRange();
} }
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment