summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/Expr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/AST/Expr.cpp')
-rw-r--r--clang/lib/AST/Expr.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 9b4de2bf4e8..d31bde283b1 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -347,10 +347,18 @@ bool Expr::hasLocalSideEffect() const {
return true;
case ObjCMessageExprClass:
return true;
- case StmtExprClass:
- // TODO: check the inside of the statement expression
- return true;
-
+ case StmtExprClass: {
+ // Statement exprs don't logically have side effects themselves, but are
+ // sometimes used in macros in ways that give them a type that is unused.
+ // For example ({ blah; foo(); }) will end up with a type if foo has a type.
+ // however, if the result of the stmt expr is dead, we don't want to emit a
+ // warning.
+ const CompoundStmt *CS = cast<StmtExpr>(this)->getSubStmt();
+ if (!CS->body_empty())
+ if (const Expr *E = dyn_cast<Expr>(CS->body_back()))
+ return E->hasLocalSideEffect();
+ return false;
+ }
case CastExprClass:
// If this is a cast to void, check the operand. Otherwise, the result of
// the cast is unused.
OpenPOWER on IntegriCloud