]> granicus.if.org Git - clang/commitdiff
fix PR4633: cast to void should silence the 'unused expression' warning.
authorChris Lattner <sabre@nondot.org>
Tue, 28 Jul 2009 18:25:28 +0000 (18:25 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 28 Jul 2009 18:25:28 +0000 (18:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@77344 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
test/Sema/unused-expr.c

index 2c473ebc428e33f7504c26c37ebd158248dcfd69..79ebb546d075d1c3c085ff0e8cb033be499008e5 100644 (file)
@@ -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;
index 9c231e960a2a467d8ea95c3c109cc9a3414ba75c..a5e5ec4e1491c42138cf35fb01a2fde7d1e9a39f 100644 (file)
@@ -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;
 }
+
+