summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-03-12 07:11:26 +0000
committerJohn McCall <rjmccall@apple.com>2010-03-12 07:11:26 +0000
commitc493a7324003732b845be1fee11df312d2846207 (patch)
tree7bb5d249e72a29e796ac65bdc600e59fd5594902 /clang/lib/AST/Expr.cpp
parent399f1f4fd3d3873f979dc3fb727094dc57f7f80e (diff)
downloadbcm5719-llvm-c493a7324003732b845be1fee11df312d2846207.tar.gz
bcm5719-llvm-c493a7324003732b845be1fee11df312d2846207.zip
Improve the unused-value check to look into comma expressions and filter out
voids in sub-expressions. Patch by Mike M! Fixes PR4806. llvm-svn: 98335
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index efd0fd1b8dc..1b3202dd428 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -788,6 +788,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
switch (getStmtClass()) {
default:
+ if (getType()->isVoidType())
+ return false;
Loc = getExprLoc();
R1 = getSourceRange();
return true;
@@ -834,8 +836,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
if (IE->getValue() == 0)
return false;
- return (BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
- BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
+ return (BO->getLHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx) ||
+ BO->getRHS()->isUnusedResultAWarning(Loc, R1, R2, Ctx));
}
if (BO->isAssignmentOp())
@@ -936,6 +938,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
return E->isUnusedResultAWarning(Loc, R1, R2, Ctx);
+ if (getType()->isVoidType())
+ return false;
Loc = cast<StmtExpr>(this)->getLParenLoc();
R1 = getSourceRange();
return true;
@@ -949,6 +953,8 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1,
R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange();
return true;
case CXXFunctionalCastExprClass: {
+ if (getType()->isVoidType())
+ return false;
const CastExpr *CE = cast<CastExpr>(this);
// If this is a cast to void or a constructor conversion, check the operand.
OpenPOWER on IntegriCloud