<div class="gmail_quote">On Thu, Jul 14, 2011 at 4:11 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com">chandlerc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="gmail_quote"><div class="im">On Thu, Jul 14, 2011 at 4:01 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div></div><div><div class="gmail_quote">On Thu, Jul 14, 2011 at 3:53 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div>On Thu, Jul 14, 2011 at 3:35 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Currently, -Wsign-compare will warn if conditional operands differ in signedness. This patch will move this warning to -Wmixed-sign-conditional </blockquote><div><br></div></div><div>Why not -Wsign-conversion ? Just wondering why we need a separate flag here.</div>
</div>
</blockquote></div></div></div>-Wsign-conversion has a separate warning that will override this one. Essentially, the conditional statement can have only have one type, so if the operands are of different signs, one will be forced to convert, which throws the warning. Here's an example:<div>
<br></div><div><div>void f(unsigned int u, int i) {</div><div> (void) (true ? u : i);</div><div>}</div></div><div><br></div><div>clang -Wsign-conversion</div><div><div>warning: operand of ? changes signedness: 'int' to 'unsigned int'</div>
<div> [-Wsign-conversion]</div><div> (void) (true ? u : i);</div><div> ~ ^</div></div></blockquote><div><br></div></div><div>Ah, cool</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>clang -Wmixed-sign-conditional</div><div><div>warning: operands of ? are integers of different signs:</div>
<div> 'unsigned int' and 'int' [-Wmixed-sign-conditional]</div><div> (void) (true ? u : i);</div><div> ^ ~ ~</div></div></blockquote></div></div><br><div>So what's the motivation for being able to get *just* these warnings out? The only bug I'm aware of was specific to -Wsign-compare warning on this construct in a compile that didn't use -Wsign-conversion, and so expected the code to compile without warnings. If -Wsign-conversion already catches this, it would seem to me that that's sufficient?</div>
</blockquote></div><br><div>The main motivation is to make -Wsign-compare only about checking signs during comparisons. Since the operands of the conditional operator aren't compared, it seems out of place to check it there.</div>