re PR c/21159 ("no effect" warning despite cast to void*)
authorJoseph Myers <joseph@codesourcery.com>
Wed, 27 Apr 2005 21:41:15 +0000 (22:41 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Wed, 27 Apr 2005 21:41:15 +0000 (22:41 +0100)
PR c/21159
* c-typeck.c (build_compound_expr): Don't warn for left-hand side
being a compound expression whose right-hand side is cast to void.

testsuite:
* gcc.dg/void-cast-1.c: New test.

From-SVN: r98886

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/void-cast-1.c [new file with mode: 0644]

index 947e032..b5ba524 100644 (file)
@@ -1,3 +1,9 @@
+2005-04-27  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21159
+       * c-typeck.c (build_compound_expr): Don't warn for left-hand side
+       being a compound expression whose right-hand side is cast to void.
+
 2005-04-27  Caroline Tice  <ctice@apple.com>
 
         * bb-reorder.c (find_rarely_executed_basic_blocks_and_crossing_edges):
index cde90a7..281d2b0 100644 (file)
@@ -3109,9 +3109,16 @@ build_compound_expr (tree expr1, tree expr2)
          statement: with -Wextra or -Wunused, we should warn if it doesn't have
         any side-effects, unless it was explicitly cast to (void).  */
       if (warn_unused_value
-           && !(TREE_CODE (expr1) == CONVERT_EXPR
-                && VOID_TYPE_P (TREE_TYPE (expr1))))
-        warning (0, "left-hand operand of comma expression has no effect");
+         && !VOID_TYPE_P (TREE_TYPE (expr1)))
+       {
+         if (TREE_CODE (expr1) == CONVERT_EXPR)
+           ; /* (void) a, b */
+         else if (TREE_CODE (expr1) == COMPOUND_EXPR
+                  && TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR)
+           ; /* (void) a, (void) b, c */
+         else
+           warning (0, "left-hand operand of comma expression has no effect");
+       }
     }
 
   /* With -Wunused, we should also warn if the left-hand operand does have
index 0febe06..b16bf69 100644 (file)
@@ -1,3 +1,8 @@
+2005-04-27  Joseph S. Myers  <joseph@codesourcery.com>
+
+       PR c/21159
+       * gcc.dg/void-cast-1.c: New test.
+
 2005-04-27  Paolo Bonzini  <bonzini@gnu.org>
 
        * gcc.dg/tree-ssa/gen-vect-25.c: Make more portable.
diff --git a/gcc/testsuite/gcc.dg/void-cast-1.c b/gcc/testsuite/gcc.dg/void-cast-1.c
new file mode 100644 (file)
index 0000000..bd4e7b3
--- /dev/null
@@ -0,0 +1,11 @@
+/* Don't warn where the left-hand side of a comma expression is a
+   comma expression whose right-hand side is cast to void.  Bug
+   21159.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+int a, b, c, d;
+int e(void) { return (void)a, b; }
+int f(void) { return (void)a, (void)b, c; }
+int g(void) { return (void)a, (void)b, (void)c, d; }