Patch for bug 21159

Daniel Jacobowitz drow@false.org
Wed Apr 27 22:26:00 GMT 2005


On Wed, Apr 27, 2005 at 09:47:31PM +0000, Joseph S. Myers wrote:
> This patch fixes bug 21159, that "(void)a, (void)b, c" newly receives
> a warning in 4.0.0 which is formally correct - "(void)a, (void)b" is a
> left-hand side of a comma expression, it has no effect and it is not
> cast to void - but useless.  The patch stops the warning for when the
> LHS is itself a comma expression with RHS cast to void.

This is probably right, but it jumped out at me...

> -           && !(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)

Previously the test was !(CONVERT_EXPR && VOID_TYPE_P).  That's the
same as !CONVERT_EXPR || !VOID_TYPE_P.  The new test is !VOID_TYPE_P
&& (!CONVERT_EXPR || !COMPOUND_EXPR).

If the left hand item has no side effects, is of void type,
and is not a CONVERT_EXPR, the previous code would have warned but the
new code won't.  I have no idea if that's possible.

-- 
Daniel Jacobowitz
CodeSourcery, LLC



More information about the Gcc-patches mailing list