From 157689c6d3a24540fd59d402e4622991e5ac9c0b Mon Sep 17 00:00:00 2001 From: Neil Booth Date: Thu, 1 Nov 2001 23:29:09 +0000 Subject: 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 --- gcc/ChangeLog | 6 ++++++ gcc/c-typeck.c | 6 ++++++ gcc/testsuite/gcc.dg/Wparentheses-1.c | 15 +++++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/Wparentheses-1.c 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 + + * c-typeck.c (default_conversion): Retain the original expression + codes. + * gcc.dg/Wparentheses.c: New tests. + 2001-11-01 David S. Miller * 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" } */ +} -- cgit v1.1