aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-07-30 22:17:18 +0000
committerAnders Carlsson <andersca@mac.com>2009-07-30 22:17:18 +0000
commit636463e4c43be15e2f0fd0b8a08667f3066d8af7 (patch)
tree6e61b62733dea4480befb57514538a3a047f8f5c /lib/Sema/SemaStmt.cpp
parent7116da1efe23f90eb22524ac9aa036153b74f482 (diff)
Factor code out into a DiagnoseUnusedExprResult function.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77628 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r--lib/Sema/SemaStmt.cpp32
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index 11497037c5..badeba79ce 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -51,6 +51,23 @@ Sema::OwningStmtResult Sema::ActOnDeclStmt(DeclGroupPtrTy dg,
return Owned(new (Context) DeclStmt(DG, StartLoc, EndLoc));
}
+void Sema::DiagnoseUnusedExprResult(const Stmt *S) {
+ const Expr *E = dyn_cast<Expr>(S);
+ if (!E)
+ return;
+
+ // Ignore expressions that have void type.
+ if (E->getType()->isVoidType())
+ return;
+
+ SourceLocation Loc;
+ SourceRange R1, R2;
+ if (!E->isUnusedResultAWarning(Loc, R1, R2))
+ return;
+
+ Diag(Loc, diag::warn_unused_expr) << R1 << R2;
+}
+
Action::OwningStmtResult
Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
MultiStmtArg elts, bool isStmtExpr) {
@@ -76,20 +93,11 @@ Sema::ActOnCompoundStmt(SourceLocation L, SourceLocation R,
}
// Warn about unused expressions in statements.
for (unsigned i = 0; i != NumElts; ++i) {
- Expr *E = dyn_cast<Expr>(Elts[i]);
- if (!E) continue;
-
- // Warn about expressions with unused results if they are non-void and if
- // this not the last stmt in a stmt expr.
- if (E->getType()->isVoidType() || (isStmtExpr && i == NumElts-1))
+ // Ignore statements that are last in a statement expression.
+ if (isStmtExpr && i == NumElts - 1)
continue;
- SourceLocation Loc;
- SourceRange R1, R2;
- if (!E->isUnusedResultAWarning(Loc, R1, R2))
- continue;
-
- Diag(Loc, diag::warn_unused_expr) << R1 << R2;
+ DiagnoseUnusedExprResult(Elts[i]);
}
return Owned(new (Context) CompoundStmt(Context, Elts, NumElts, L, R));