Hi!

This is my first proposed patch for
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17896. I was willing to
do it using "APPEARS_TO_BE_BOOLEAN_EXPR_P(CODE, ARG)" to check
booleans but gcc doesn't allow (bootstraping fails). Hence I am using
"TREE_CODE_CLASS (CODE) == tcc_comparison"



-- 
Thanks and Regards,
Prasad Ghangal
Index: gcc/c-family/c-common.c
===================================================================
--- gcc/c-family/c-common.c	(revision 232768)
+++ gcc/c-family/c-common.c	(working copy)
@@ -11596,6 +11596,11 @@
 	       || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
 	warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
 		 "suggest parentheses around arithmetic in operand of %<|%>");
+      /* Check cases like (x<y) | (x<z)*/
+      else if(TREE_CODE_CLASS (code_left) == tcc_comparison
+	       && (TREE_CODE_CLASS (code_right) == tcc_comparison))
+	warning_at (loc, OPT_Wparentheses,
+		 "suggest %<||%> instead of %<|%> when joining booleans");
       /* Check cases like x|y==z */
       else if (TREE_CODE_CLASS (code_left) == tcc_comparison)
 	warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
@@ -11642,6 +11647,11 @@
       else if (code_right == MINUS_EXPR)
 	warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
 		 "suggest parentheses around %<-%> in operand of %<&%>");
+      /* Check cases like (x<y) & (x<z)*/
+      else if(TREE_CODE_CLASS (code_left) == tcc_comparison 
+	      && TREE_CODE_CLASS (code_right) == tcc_comparison)
+	warning_at (loc, OPT_Wparentheses,
+		 "suggest %<&&%> instead of %<&%> when joining booleans");
       /* Check cases like x&y==z */
       else if (TREE_CODE_CLASS (code_left) == tcc_comparison)
 	warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,

Reply via email to