aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2005-04-27 22:41:15 +0100
committerJoseph Myers <jsm28@gcc.gnu.org>2005-04-27 22:41:15 +0100
commit47aecf47d196c05b7b388e4fefbdce2f075bd4b0 (patch)
treece276778b8df2b8bd816052b690271a7aecc28d3 /gcc
parentc7466deed4c713f843bf5256ffddbeca135d1371 (diff)
downloadgcc-47aecf47d196c05b7b388e4fefbdce2f075bd4b0.zip
gcc-47aecf47d196c05b7b388e4fefbdce2f075bd4b0.tar.gz
gcc-47aecf47d196c05b7b388e4fefbdce2f075bd4b0.tar.bz2
re PR c/21159 ("no effect" warning despite cast to void*)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-typeck.c13
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/void-cast-1.c11
4 files changed, 32 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 947e032..b5ba524 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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):
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index cde90a7..281d2b0 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 0febe06..b16bf69 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..bd4e7b3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/void-cast-1.c
@@ -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; }