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
This commit is contained in:
Joseph Myers 2005-04-27 22:41:15 +01:00 committed by Joseph Myers
parent c7466deed4
commit 47aecf47d1
4 changed files with 32 additions and 3 deletions

View 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):

View 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

View 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.

View File

@ -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; }