]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
typeck.c (convert_for_assignment): Only warn about a = b = c when converting to bool.
authorIan Lance Taylor <iant@google.com>
Tue, 23 Jan 2007 21:46:51 +0000 (21:46 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 23 Jan 2007 21:46:51 +0000 (21:46 +0000)
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

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/Wparentheses-24.C [new file with mode: 0644]

index 906aabf35fbf73b94728f469238e8f1713f6225f..65366bb4025e38085f93d87ee73dd35b2a8ad06b 100644 (file)
@@ -1,3 +1,8 @@
+2007-01-23  Ian Lance Taylor  <iant@google.com>
+
+       * typeck.c (convert_for_assignment): Only warn about a = b = c
+       when converting to bool.
+
 2007-01-23  Roger Sayle  <roger@eyesopen.com>
 
        * call.c (null_ptr_cst_p): Replace use of TREE_CONSTANT_OVERFLOW with
index fa58a57e4d6f6031da8478f4f154b3f46516f562..709d25b4dd200b9ecafcc21e7e23908010c91e2d 100644 (file)
@@ -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");
index 11b3bdab444f90f418cf541f6af2d4081b640223..81f1370986c9efee4a35f9abc64d01e64a2b51be 100644 (file)
@@ -1,3 +1,7 @@
+2007-01-23  Ian Lance Taylor  <iant@google.com>
+
+       * g++.dg/warn/Wparentheses-24.C: New test.
+
 2007-01-23  Richard Guenther  <rguenther@suse.de>
 
        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 (file)
index 0000000..4019d3d
--- /dev/null
@@ -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;
+}