diff options
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index 350f16d93d8..c58bf464004 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -488,6 +488,20 @@ StmtResult Sema::ActOnAttributedStmt(SourceLocation AttrLoc, return LS; } +namespace { +class CommaVisitor : public EvaluatedExprVisitor<CommaVisitor> { + typedef EvaluatedExprVisitor<CommaVisitor> Inherited; + Sema &SemaRef; +public: + CommaVisitor(Sema &SemaRef) : Inherited(SemaRef.Context), SemaRef(SemaRef) {} + void VisitBinaryOperator(BinaryOperator *E) { + if (E->getOpcode() == BO_Comma) + SemaRef.DiagnoseCommaOperator(E->getLHS(), E->getExprLoc()); + EvaluatedExprVisitor<CommaVisitor>::VisitBinaryOperator(E); + } +}; +} + StmtResult Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, Stmt *thenStmt, SourceLocation ElseLoc, @@ -502,6 +516,11 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, FullExprArg CondVal, Decl *CondVar, } Expr *ConditionExpr = CondResult.getAs<Expr>(); if (ConditionExpr) { + + if (!Diags.isIgnored(diag::warn_comma_operator, + ConditionExpr->getExprLoc())) + CommaVisitor(*this).Visit(ConditionExpr); + DiagnoseUnusedExprResult(thenStmt); if (!elseStmt) { @@ -1240,6 +1259,10 @@ Sema::ActOnWhileStmt(SourceLocation WhileLoc, FullExprArg Cond, return StmtError(); CheckBreakContinueBinding(ConditionExpr); + if (ConditionExpr && + !Diags.isIgnored(diag::warn_comma_operator, ConditionExpr->getExprLoc())) + CommaVisitor(*this).Visit(ConditionExpr); + DiagnoseUnusedExprResult(Body); if (isa<NullStmt>(Body)) @@ -1642,6 +1665,11 @@ Sema::ActOnForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, return StmtError(); } + if (SecondResult.get() && + !Diags.isIgnored(diag::warn_comma_operator, + SecondResult.get()->getExprLoc())) + CommaVisitor(*this).Visit(SecondResult.get()); + Expr *Third = third.release().getAs<Expr>(); DiagnoseUnusedExprResult(First); |