aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-28 18:25:28 +0000
committerChris Lattner <sabre@nondot.org>2009-07-28 18:25:28 +0000
commitfb84664349ca6f37f5ec4df440f6c362cca62470 (patch)
treeafbecc17c6430205bf4001d9a0e3b70c1ef5b5d6
parent41f55d3d89d53ac242db8244f823555904200744 (diff)
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
-rw-r--r--lib/AST/Expr.cpp7
-rw-r--r--test/Sema/unused-expr.c7
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<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/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;
}
+
+