From 47aecf47d196c05b7b388e4fefbdce2f075bd4b0 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Wed, 27 Apr 2005 22:41:15 +0100 Subject: [PATCH] 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 --- gcc/ChangeLog | 6 ++++++ gcc/c-typeck.c | 13 ++++++++++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/void-cast-1.c | 11 +++++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/void-cast-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 947e032a592..b5ba524960b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2005-04-27 Joseph S. Myers + + 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 * bb-reorder.c (find_rarely_executed_basic_blocks_and_crossing_edges): diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index cde90a763d3..281d2b0cf14 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 0febe06972c..b16bf69aba5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2005-04-27 Joseph S. Myers + + PR c/21159 + * gcc.dg/void-cast-1.c: New test. + 2005-04-27 Paolo Bonzini * 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 00000000000..bd4e7b3bf7a --- /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 */ +/* { 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; }