From: Ian Lance Taylor Date: Tue, 23 Jan 2007 21:46:51 +0000 (+0000) Subject: typeck.c (convert_for_assignment): Only warn about a = b = c when converting to bool. X-Git-Tag: releases/gcc-4.3.0~7304 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a99e5cb4d8364de480cbad919100b74ce7b0d378;p=thirdparty%2Fgcc.git typeck.c (convert_for_assignment): Only warn about a = b = c when converting to bool. 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. From-SVN: r121087 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 906aabf35fbf..65366bb4025e 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 fa58a57e4d6f..709d25b4dd20 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 11b3bdab444f..81f1370986c9 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 000000000000..4019d3d82862 --- /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; +}