c-typeck.c (build_compound_expr): Correct logic in last change.
authorJoseph Myers <joseph@codesourcery.com>
Thu, 28 Apr 2005 00:45:48 +0000 (01:45 +0100)
committerJoseph Myers <jsm28@gcc.gnu.org>
Thu, 28 Apr 2005 00:45:48 +0000 (01:45 +0100)
* c-typeck.c (build_compound_expr): Correct logic in last change.

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

From-SVN: r98901

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

index 5da37d415a84f42d452a43e61a7e2e83d523f056..95fe5f5742d9aca18c86a4dffb910602dadb0c72 100644 (file)
@@ -1,3 +1,7 @@
+2005-04-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       * c-typeck.c (build_compound_expr): Correct logic in last change.
+
 2005-04-27  James E. Wilson  <wilson@specifixinc.com>
 
        * config/ia64/ia64.c (update_set_flags): Delete ppred and pcond
index 281d2b0cf1403ead1f9c6f7a649f9be103330a80..3a5d11d1f421b7ac0286c17f57f2c30efbb3999f 100644 (file)
@@ -3108,12 +3108,13 @@ build_compound_expr (tree expr1, tree expr2)
       /* The left-hand operand of a comma expression is like an expression
          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
-         && !VOID_TYPE_P (TREE_TYPE (expr1)))
+      if (warn_unused_value)
        {
-         if (TREE_CODE (expr1) == CONVERT_EXPR)
+         if (VOID_TYPE_P (TREE_TYPE (expr1))
+             && TREE_CODE (expr1) == CONVERT_EXPR)
            ; /* (void) a, b */
-         else if (TREE_CODE (expr1) == COMPOUND_EXPR
+         else if (VOID_TYPE_P (TREE_TYPE (expr1))
+                  && TREE_CODE (expr1) == COMPOUND_EXPR
                   && TREE_CODE (TREE_OPERAND (expr1, 1)) == CONVERT_EXPR)
            ; /* (void) a, (void) b, c */
          else
index b16bf69aba515213bd6b6aed04cd516fbe392ccb..1f7bc01814d9734a1d2f6e4d78e90884bfd1096e 100644 (file)
@@ -1,3 +1,7 @@
+2005-04-28  Joseph S. Myers  <joseph@codesourcery.com>
+
+       * gcc.dg/void-cast-2.c: New test.
+
 2005-04-27  Joseph S. Myers  <joseph@codesourcery.com>
 
        PR c/21159
diff --git a/gcc/testsuite/gcc.dg/void-cast-2.c b/gcc/testsuite/gcc.dg/void-cast-2.c
new file mode 100644 (file)
index 0000000..c51e91a
--- /dev/null
@@ -0,0 +1,8 @@
+/* Test further cases of warnings for comma expressions, with and
+   without casts to void.  */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+int a, b, c, d;
+int e(void) { return (char)a, b; } /* { dg-warning "warning: left-hand operand of comma expression has no effect" } */
+int f(void) { return (a ? (void)b : (void)c), d; } /* { dg-warning "warning: left-hand operand of comma expression has no effect" } */