diff options
| author | Chris Lattner <sabre@nondot.org> | 2009-07-28 18:25:28 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2009-07-28 18:25:28 +0000 |
| commit | 2706a550711dd4c85924b78cc1787267e62aec56 (patch) | |
| tree | 060f267010b2d3c3c0fdc4aceae3170eb8af904f | |
| parent | 1d0f16f22aa46c7cd6ef016fab408bec3990849c (diff) | |
| download | bcm5719-llvm-2706a550711dd4c85924b78cc1787267e62aec56.tar.gz bcm5719-llvm-2706a550711dd4c85924b78cc1787267e62aec56.zip | |
fix PR4633: cast to void should silence the 'unused expression' warning.
llvm-svn: 77344
| -rw-r--r-- | clang/lib/AST/Expr.cpp | 7 | ||||
| -rw-r--r-- | clang/test/Sema/unused-expr.c | 7 |
2 files changed, 10 insertions, 4 deletions
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 2c473ebc428..79ebb546d07 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -593,11 +593,10 @@ bool Expr::isUnusedResultAWarning(SourceLocation &Loc, SourceRange &R1, return true; } case CStyleCastExprClass: - // If this is a cast to void, check the operand. Otherwise, the result of - // the cast is unused. + // If this is an explicit cast to void, allow it. People do this when they + // think they know what they're doing :). if (getType()->isVoidType()) - return cast<CastExpr>(this)->getSubExpr() - ->isUnusedResultAWarning(Loc, R1, R2); + return false; Loc = cast<CStyleCastExpr>(this)->getLParenLoc(); R1 = cast<CStyleCastExpr>(this)->getSubExpr()->getSourceRange(); return true; diff --git a/clang/test/Sema/unused-expr.c b/clang/test/Sema/unused-expr.c index 9c231e960a2..a5e5ec4e149 100644 --- a/clang/test/Sema/unused-expr.c +++ b/clang/test/Sema/unused-expr.c @@ -43,4 +43,11 @@ void nowarn(unsigned char* a, unsigned char* b) { unsigned char c = 1; *a |= c, *b += c; + + + // PR4633 + int y, x; + ((void)0), y = x; } + + |

