public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix Bug 17896: The expression (a>0 & b>0) should give clearer warning message (-Wparentheses)
@ 2016-01-30 13:35 Prasad Ghangal
  2016-02-20 14:55 ` Prasad Ghangal
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Prasad Ghangal @ 2016-01-30 13:35 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

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

[-- Attachment #2: bug17896.patch --]
[-- Type: text/x-patch, Size: 1462 bytes --]

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,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-13 19:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-30 13:35 [PATCH] Fix Bug 17896: The expression (a>0 & b>0) should give clearer warning message (-Wparentheses) Prasad Ghangal
2016-02-20 14:55 ` Prasad Ghangal
2016-02-20 22:07 ` David Malcolm
2016-02-21 17:03   ` Prasad Ghangal
2016-07-13 19:46 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).