On 26 January 2016 at 00:45, Prasad Ghangal <prasad.ghan...@gmail.com> wrote: > Hi! > > I would like to solve "Bug 17896 - The expression (a>0 & b>0) should > give clearer warning message (-Wparentheses)" > (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=17896) but I am new to > gcc internals. > > Can someone please guide me how to do it? You would perhaps need to modify c-common.c:warn_about_parentheses (). my untested patch gives: f.c: In function ‘main’: f.c:5:13: warning: suggest && instead of & [-Wparentheses] if (a > b & a > c) ^ You will probably need to extend along similar lines.
Thanks, Prathamesh > > -- > Thanks and Regards, > Prasad Ghangal
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 378afae..9444f29 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -11642,6 +11642,10 @@ warn_about_parentheses (location_t loc, enum tree_code code, else if (code_right == MINUS_EXPR) warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses, "suggest parentheses around %<-%> in operand of %<&%>"); + else if (TREE_CODE_CLASS (code_left) == tcc_comparison + && TREE_CODE_CLASS (code_right) == tcc_comparison) + warning_at (loc, OPT_Wparentheses, + "suggest && instead of &"); /* 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,