This is the mail archive of the
mailing list for the GCC project.
Re: [C/C++ PATCH] Implement -Wbool-compare (PR c++/62153)
- From: Marek Polacek <polacek at redhat dot com>
- To: Manuel López-Ibáñez <lopezibanez at gmail dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>, "Joseph S. Myers" <joseph at codesourcery dot com>
- Date: Tue, 19 Aug 2014 16:10:40 +0200
- Subject: Re: [C/C++ PATCH] Implement -Wbool-compare (PR c++/62153)
- Authentication-results: sourceware.org; auth=none
- References: <20140818200433 dot GD11974 at redhat dot com> <CAESRpQCKZE=Z0tqev2-aijrku5Pw50naDwJXms89BEwOrO5k8g at mail dot gmail dot com> <20140819045818 dot GF11974 at redhat dot com> <CAESRpQBLYLoiRxECYoHnt_1WwMSEoMk7FVZEw-tAB9VsYwuVqA at mail dot gmail dot com>
On Tue, Aug 19, 2014 at 11:08:39AM +0200, Manuel López-Ibáñez wrote:
> > Not sure about that: it matters whether the CST is a LHS or a RHS
> > - because we want to say if the comparison is always true or false.
> > I tried to introduce some bool flag, but that didn't really help
> > readability IMHO. (The tree_int_cst_sgn is compared to 1 and -1, or
> > to -1 and 1.)
> Oh, yes. I missed that. Sorry. What about?
> tree op = (TREE_CODE (op0) == INTEGER_CST) ? op0
> : (TREE_CODE (op1) == INTEGER_CST) ? op1 : NULL_TREE;
> if (op == NULL_TREE)
> if (!integer_zerop (op) && !integer_onep(op))
> int sign = (TREE_CODE (op0) == INTEGER_CST)
> ? tree_int_cst_sgn (op) : -tree_int_cst_sgn (op);
> if (code == EQ_EXPR
> || ((code == GT_EXPR || code == GE_EXPR)
> && sign < 0)
> || ((code == LT_EXPR || code == LE_EXPR)
> && sign > 0))
> or some variation of the above could work, no?
Ok, I don't feel strongly about it, so I tweaked the code according to
the above. I'll post it later today. Thanks,