diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2001-11-01 23:29:09 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2001-11-01 23:29:09 +0000 |
commit | 157689c6d3a24540fd59d402e4622991e5ac9c0b (patch) | |
tree | b44068ffbe582945acabf838b345c59fe2591f26 | |
parent | edf1c8dff83d1bfd2d86da111c11427d827bed68 (diff) | |
download | gcc-157689c6d3a24540fd59d402e4622991e5ac9c0b.zip gcc-157689c6d3a24540fd59d402e4622991e5ac9c0b.tar.gz gcc-157689c6d3a24540fd59d402e4622991e5ac9c0b.tar.bz2 |
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
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-typeck.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/Wparentheses-1.c | 15 |
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 730d14e..e7d66f8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 48fd3b7..37810f6 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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) diff --git a/gcc/testsuite/gcc.dg/Wparentheses-1.c b/gcc/testsuite/gcc.dg/Wparentheses-1.c new file mode 100644 index 0000000..d6e86eb --- /dev/null +++ b/gcc/testsuite/gcc.dg/Wparentheses-1.c @@ -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" } */ +} |