re PR c/3170 (bogus "suggest parentheses" warning)

PR c/3170
	PR c/3422
	* c-typeck.c (default_conversion): Retain the original expression
	codes.
	* gcc.dg/Wparentheses-1.c: New tests.

From-SVN: r46705
This commit is contained in:
Neil Booth 2001-11-01 23:29:09 +00:00 committed by Neil Booth
parent edf1c8dff8
commit 157689c6d3
3 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,9 @@
2001-11-01 Neil Booth <neil@daikokuya.demon.co.uk>
* c-typeck.c (default_conversion): Retain the original expression
codes.
* gcc.dg/Wparentheses.c: New tests.
2001-11-01 David S. Miller <davem@redhat.com>
* doc/install.texi (Specific, sparc-sun-solaris2*): Bring

View File

@ -847,6 +847,7 @@ tree
default_conversion (exp)
tree exp;
{
tree orig_exp;
tree type = TREE_TYPE (exp);
enum tree_code code = TREE_CODE (type);
@ -868,11 +869,16 @@ default_conversion (exp)
Do not use STRIP_NOPS here! It will remove conversions from pointer
to integer and cause infinite recursion. */
orig_exp = exp;
while (TREE_CODE (exp) == NON_LVALUE_EXPR
|| (TREE_CODE (exp) == NOP_EXPR
&& TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
exp = TREE_OPERAND (exp, 0);
/* Preserve the original expression code. */
if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (TREE_CODE (exp))))
C_SET_EXP_ORIGINAL_CODE (exp, C_EXP_ORIGINAL_CODE (orig_exp));
/* Normally convert enums to int,
but convert wide enums to something wider. */
if (code == ENUMERAL_TYPE)

View File

@ -0,0 +1,15 @@
/* Copyright (C) 2001 Free Software Foundation, Inc. */
/* { dg-do compile } */
/* { dg-options -Wparentheses } */
/* Source: Neil Booth, 1 Nov 2001. PR 3170, 3422 - bogus warnings
about suggesting parentheses. */
int foo (int a, int b)
{
int c = (a && b) || 0; /* { dg-bogus "suggest parentheses" } */
c = a && b || 0; /* { dg-warning "suggest parentheses" } */
return (a && b && 1) || 0; /* { dg-bogus "suggest parentheses" } */
}