<div class="gmail_quote">On Wed, Jul 13, 2011 at 10:08 PM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.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 class="h5"><br>
On Jul 13, 2011, at 5:15 PM, Richard Trieu wrote:<br>
<br>
> For code such as:<br>
><br>
> void f(unsigned int u, int i) {<br>
>   (void) (true ? u : i);<br>
> }<br>
><br>
> When run with -Wsign-compare, Clang gives the following warning.<br>
><br>
> warning: operands of ? are integers of different signs:<br>
>       'unsigned int' and 'int' [-Wsign-compare]<br>
>   (void) (true ? u : i);<br>
>                ^ ~   ~<br>
><br>
> Yet, no comparison is going on between u and i, so the warning seems out of place for grouping with -Wsign-compare.  I think that it would be better is this warning was pulled out of the -Wsign-compare diagnostic group.  Also, gcc's -Wsign-compare does not warn on this code, so this change will make Clang's sign compare closer to gcc's.  Does this seem reasonable?<br>

<br>
</div></div>gcc's -Wsign-compare does warn on this code if you make the condition non-trivial.  Clang is just missing that special case.<br>
<font color="#888888"><br>
John.<br>
</font></blockquote></div><br><div>Could you give an example of a non-trivial case that gcc does warn on?  I've tried:</div><div><br></div><div><div>void f(bool b, unsigned int u, int i) {</div><div>  (void) (b ? u : i);</div>
<div>}</div></div><div><br></div><div><div>void f(unsigned int u, int i) {</div><div>  (void) ((i > 5) ? u : i);</div><div>}</div></div><div><br></div><div>but both don't give an warning from gcc -Wsign-compare.  Clang's -Wsign-compare warns on both.</div>