mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-01-28 12:04:08 +08:00
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:
parent
edf1c8dff8
commit
157689c6d3
@ -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>
|
2001-11-01 David S. Miller <davem@redhat.com>
|
||||||
|
|
||||||
* doc/install.texi (Specific, sparc-sun-solaris2*): Bring
|
* doc/install.texi (Specific, sparc-sun-solaris2*): Bring
|
||||||
|
@ -847,6 +847,7 @@ tree
|
|||||||
default_conversion (exp)
|
default_conversion (exp)
|
||||||
tree exp;
|
tree exp;
|
||||||
{
|
{
|
||||||
|
tree orig_exp;
|
||||||
tree type = TREE_TYPE (exp);
|
tree type = TREE_TYPE (exp);
|
||||||
enum tree_code code = TREE_CODE (type);
|
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
|
Do not use STRIP_NOPS here! It will remove conversions from pointer
|
||||||
to integer and cause infinite recursion. */
|
to integer and cause infinite recursion. */
|
||||||
|
orig_exp = exp;
|
||||||
while (TREE_CODE (exp) == NON_LVALUE_EXPR
|
while (TREE_CODE (exp) == NON_LVALUE_EXPR
|
||||||
|| (TREE_CODE (exp) == NOP_EXPR
|
|| (TREE_CODE (exp) == NOP_EXPR
|
||||||
&& TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
|
&& TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
|
||||||
exp = TREE_OPERAND (exp, 0);
|
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,
|
/* Normally convert enums to int,
|
||||||
but convert wide enums to something wider. */
|
but convert wide enums to something wider. */
|
||||||
if (code == ENUMERAL_TYPE)
|
if (code == ENUMERAL_TYPE)
|
||||||
|
15
gcc/testsuite/gcc.dg/Wparentheses-1.c
Normal file
15
gcc/testsuite/gcc.dg/Wparentheses-1.c
Normal 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" } */
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user