From: Argyrios Kyrtzidis Date: Sun, 19 Sep 2010 21:21:10 +0000 (+0000) Subject: Warn when an expression result in a LabelStmt is unused. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d2827af6f96d441d72315dbe6d8505c3be0f2aa6;p=clang Warn when an expression result in a LabelStmt is unused. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114314 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 4c6822c041..b31ec2314d 100644 --- a/lib/AST/Expr.cpp +++ b/lib/AST/Expr.cpp @@ -1225,9 +1225,13 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, // however, if the result of the stmt expr is dead, we don't want to emit a // warning. const CompoundStmt *CS = cast(this)->getSubStmt(); - if (!CS->body_empty()) + if (!CS->body_empty()) { if (const Expr *E = dyn_cast(CS->body_back())) return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); + if (const LabelStmt *Label = dyn_cast(CS->body_back())) + if (const Expr *E = dyn_cast(Label->getSubStmt())) + return E->isUnusedResultAWarning(Loc, R1, R2, Ctx); + } if (getType()->isVoidType()) return false; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 8ec12a460d..47ea4f2c25 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -67,6 +67,9 @@ void Sema::ActOnForEachDeclStmt(DeclGroupPtrTy dg) { } void Sema::DiagnoseUnusedExprResult(const Stmt *S) { + if (const LabelStmt *Label = dyn_cast_or_null(S)) + return DiagnoseUnusedExprResult(Label->getSubStmt()); + const Expr *E = dyn_cast_or_null(S); if (!E) return; diff --git a/test/Sema/warn-unused-value.c b/test/Sema/warn-unused-value.c index 1a7e745785..7c36b6983e 100644 --- a/test/Sema/warn-unused-value.c +++ b/test/Sema/warn-unused-value.c @@ -52,6 +52,9 @@ void pr4806() { volatile int* pj = &j; *pi; // expected-warning {{expression result unused}} *pj; + + foo_label: + i; // expected-warning {{expression result unused}} } // Don't warn about unused '||', '&&' expressions that contain assignments.