From fb84664349ca6f37f5ec4df440f6c362cca62470 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 28 Jul 2009 18:25:28 +0000 Subject: [PATCH] fix PR4633: cast to void should silence the 'unused expression' warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77344 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/Expr.cpp | 7 +++---- test/Sema/unused-expr.c | 7 +++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/AST/Expr.cpp b/lib/AST/Expr.cpp index 2c473ebc42..79ebb546d0 100644 --- a/lib/AST/Expr.cpp +++ b/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(this)->getSubExpr() - ->isUnusedResultAWarning(Loc, R1, R2); + return false; Loc = cast(this)->getLParenLoc(); R1 = cast(this)->getSubExpr()->getSourceRange(); return true; diff --git a/test/Sema/unused-expr.c b/test/Sema/unused-expr.c index 9c231e960a..a5e5ec4e14 100644 --- a/test/Sema/unused-expr.c +++ b/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; } + + -- 2.40.0