This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH RFA: Fix -Wparentheses fallout


The -Wparentheses patch I recently checked in accidentally warns about
    a = b = c;
where all variables have type bool.  That is not intended.  This patch
fixes the problem, and adds test cases.

Thanks to Ben Elliston for noticing the problem.

Bootstrapped and tested on i686-pc-linux-gnu.

OK for mainline?

Ian


cp/ChangeLog:
2007-01-07  Ian Lance Taylor  <iant@google.com>

	* typeck.c (convert_for_assignment): Only warn about a = b = c
	when converting to bool.

testsuite/ChangeLog:
2007-01-07  Ian Lance Taylor  <iant@google.com>

	* g++.dg/warn/Wparentheses-24.C: New test.


Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c	(revision 120526)
+++ gcc/cp/typeck.c	(working copy)
@@ -6378,11 +6378,13 @@ convert_for_assignment (tree type, tree 
 		 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: gcc/testsuite/g++.dg/warn/Wparentheses-24.C
===================================================================
--- gcc/testsuite/g++.dg/warn/Wparentheses-24.C	(revision 0)
+++ gcc/testsuite/g++.dg/warn/Wparentheses-24.C	(revision 0)
@@ -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;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]