<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">On Mon, Oct 7, 2019 at 6:58 PM Dávid Bolvanský <<a href="mailto:david.bolvansky@gmail.com">david.bolvansky@gmail.com</a>> wrote:<br>>> FWIW I found the "always evaluates to 'true'" bit important to<br>>> understand the warning.<br>><br>> Yeah. I moved this check somewhere else, so we can print precise message:<br>> r373973 should emit "bitwise negation of a boolean expression always<br>> evaluates to 'true'; did you mean logical negation?" where possible.<br>> In the suspicious case like int i = ~b there is a general message<br>> "bitwise negation of a boolean expression; did you mean logical<br>> negation?".<br>><br>> I like it now. What do you think? fine for you?<br><br>I see. Yes, all the cases I tried produce appropriate diagnostics. I like it!</div><div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hm, there is no "bitwise negation of a boolean expression always<br>
evaluates to 'true'; did you mean logical negation?" for chromium<br>
case [ <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=1011810">https://bugs.chromium.org/p/chromium/issues/detail?id=1011810</a> ]. I will try to fix it.</blockquote><div><br></div><div>The important part there seems to be that the result of `~b` (which must be either -1 or -2) is used as the operand to `!=` or `==`.</div><div>My opinion is that it is not worth the extra complication just to improve the error message for this case.</div><div>It would be interesting to do some kind of <i><b>general</b></i>-purpose dataflow before emitting diagnostics...</div><div>I notice that Clang's optimizer is smart enough to optimize<br></div><div>    bool foo(bool a, bool b) {</div><div>        return a == ~b;</div><div>    }</div><div>    bool bar(int x) {</div><div>        return x + 1 < -INT_MAX;</div><div>    }</div><div>into `return 0`. If it could propagate that information up and produce a diagnostic, users might appreciate that. But the challenge as always is that we can never tell if the user might sometimes be doing that sort of thing on purpose (in inlined code, in macros, in generated code, etc).</div><div><br></div><div>my $.02,</div><div>–Arthur</div></div></div></div></div></div>