From b5af670241b1f4a1884d24df93843bc651715bf2 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 23 Jan 2007 21:46:51 +0000 Subject: [PATCH] cp/: * typeck.c (convert_for_assignment): Only warn about a = b = c when converting to bool. testsuite/: * g++.dg/warn/Wparentheses-24.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@121087 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/typeck.c | 6 ++++-- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/warn/Wparentheses-24.C | 14 ++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/warn/Wparentheses-24.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 906aabf35fb..65366bb4025 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2007-01-23 Ian Lance Taylor + + * typeck.c (convert_for_assignment): Only warn about a = b = c + when converting to bool. + 2007-01-23 Roger Sayle * call.c (null_ptr_cst_p): Replace use of TREE_CONSTANT_OVERFLOW with diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index fa58a57e4d6..709d25b4dd2 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -6380,11 +6380,13 @@ convert_for_assignment (tree type, tree rhs, errtype); } - /* If -Wparentheses, warn about a = b = c when a has type bool. */ + /* If -Wparentheses, warn about a = b = c when a has type bool and b + does not. */ if (warn_parentheses && type == boolean_type_node && TREE_CODE (rhs) == MODIFY_EXPR - && !TREE_NO_WARNING (rhs)) + && !TREE_NO_WARNING (rhs) + && TREE_TYPE (rhs) != boolean_type_node) { warning (OPT_Wparentheses, "suggest parentheses around assignment used as truth value"); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 11b3bdab444..81f1370986c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2007-01-23 Ian Lance Taylor + + * g++.dg/warn/Wparentheses-24.C: New test. + 2007-01-23 Richard Guenther PR testsuite/30560 diff --git a/gcc/testsuite/g++.dg/warn/Wparentheses-24.C b/gcc/testsuite/g++.dg/warn/Wparentheses-24.C new file mode 100644 index 00000000000..4019d3d8286 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wparentheses-24.C @@ -0,0 +1,14 @@ +// { dg-do compile } +// { dg-options "-Wparentheses" } + +extern int foo (int); + +bool a, b, c; + +bool +bar () +{ + c = a = b; + foo (0); + return a = b; +} -- 2.11.4.GIT