<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 7, 2014 at 10:26 AM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div><div class="im"><div>On Jan 7, 2014, at 8:40 AM, Nico Weber <<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>> wrote:</div>
<br><blockquote type="cite"><div dir="ltr">No opinion on the actual issue, but…<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 6, 2014 at 11:49 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@gmail.com" target="_blank">chandlerc@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Currently Clang and GCC warn about:<div><br>
</div><div>(a || b && c)</div><div><br></div><div>Due to the very common mistake by programmers which ignores the relative operator precedence of || and &&. This forces the user to place explicit parentheses to group either (a || b) or (b && c) to be evaluated first.</div>
<div><br></div><div>However, GCC warns and Clang is silent about this:</div><div><br></div><div>(a || b && 1)</div><div><br></div><div>Worse, the same is true for:</div><div><br></div><div>(a || b && "foo")</div>
<div><br></div><div>Now, I find Clang's rationale seems somewhat reasonable: the grouping doesn't change the truth table for this expression. However, I find this clever interpretation problematic for several reasons:</div>
<div><br></div><div>1) It's a complex rule to teach programmers with dubious gains. This exception doesn't realistically make the warning's false positives rare, it just eliminates one common (but not the only common) pattern. On the flip side, it is not a trivial rule to teach or predict for programmers. *Any* constant that we can evaluate to true will satisfy this.</div>
<div><br></div><div>2) If the programmer expected the || to be evaluated first, they might well also expect the "a" expression to be evaluated first and short circuiting to take place. Even though the truth table is unimpacted, 'assert(!ptr || ptr->empty() && "foo");' can segfault, which I think might surprise users.</div>
<div><br></div><div>3) It makes it annoying to track warnings in both Clang and GCC. If you mostly develop with Clang, but someone else checks out your code with GCC it'll suddenly start warning (much like it just did in a recent commit.)</div>
</div></blockquote><div><br></div><div>…this isn't a convincing argument. Several of clang's warnings are by design smarter and less noisy than gcc's, with the effect that the clang warning is useful while the gcc counterpart isn't (e.g. Woverloaded-virtual, but there are many more).</div>
</div></div></div></blockquote><div><br></div></div><div>+1</div><div><br></div><div>For the ubiquitous assert pattern like:</div><div><br></div><div>assert(a || b && “god help us”)</div><div><br></div><div>I don’t think this is confusing and the warning offers no value; IMHO adding the parentheses is more like noise than improving clarity.</div>
</div></div></blockquote><div><br></div><div>FWIW, I recall seeing someone somewhere (can't remember when/where/what context) say something along the lines of "unlike GCC, Clang is smart enough to ease off on -Wparentheses when inside the assert macro", which I take to mean that this is a useful behavior.</div>
<div><br></div><div>-- Sean Silva</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><br></div><div>Is it out-of-the-question to file a report on GCC to see if they would consider also silencing the warning, and in the meantime turn it off for gcc ?</div>
<div class="im"><br><blockquote type="cite"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">
<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">
<div><br></div><div><br></div><div>Thoughts? I'm happy to fix this, the change is trivial in SemaExpr.cpp, but wanted to get some confirmation from Richard and Argyrios who have worked on this warning that such a change would be OK.</div>
<span><font color="#888888">
<div><br></div><div>-Chandler</div></font></span></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div></div><br></div><br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>