diff options
| author | Chris Lattner <sabre@nondot.org> | 2008-07-26 19:51:01 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2008-07-26 19:51:01 +0000 |
| commit | 944d306371e3a10f63a9f65799643a45971a314f (patch) | |
| tree | 876168cd548c2155629dd5ecb0ae301ed51b5d54 /clang/lib/Sema | |
| parent | 06afbebbdde63cd4ad93c12db65129ca2c318015 (diff) | |
| download | bcm5719-llvm-944d306371e3a10f63a9f65799643a45971a314f.tar.gz bcm5719-llvm-944d306371e3a10f63a9f65799643a45971a314f.zip | |
fix some problems handling stmtexprs with labels (PR2374), and
improve 'expression unused' diagnostics for stmtexprs.
llvm-svn: 54098
Diffstat (limited to 'clang/lib/Sema')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 25a86fabdb7..bb5ed509e54 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2334,9 +2334,15 @@ Sema::ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, StmtTy *substmt, // as the type of the stmtexpr. QualType Ty = Context.VoidTy; - if (!Compound->body_empty()) - if (Expr *LastExpr = dyn_cast<Expr>(Compound->body_back())) + if (!Compound->body_empty()) { + Stmt *LastStmt = Compound->body_back(); + // If LastStmt is a label, skip down through into the body. + while (LabelStmt *Label = dyn_cast<LabelStmt>(LastStmt)) + LastStmt = Label->getSubStmt(); + + if (Expr *LastExpr = dyn_cast<Expr>(LastStmt)) Ty = LastExpr->getType(); + } return new StmtExpr(Compound, Ty, LPLoc, RPLoc); } |

