<br><br><div class="gmail_quote">On Tue, Sep 25, 2012 at 5:29 PM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Sep 18, 2012 at 6:37 PM, Fariborz Jahanian <<a href="mailto:fjahanian@apple.com">fjahanian@apple.com</a>> wrote:<br>
> Author: fjahanian<br>
> Date: Tue Sep 18 12:37:21 2012<br>
> New Revision: 164143<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=164143&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=164143&view=rev</a><br>
> Log:<br>
> c: warn when an integer value comparison with an<br>
> integral expression have the obvious result.<br>
> Patch reviewed by John McCall off line.<br>
> // rdar://12202422<br>
<br>
This triggers a couple of warnings in Chromium. (We're tracking it at<br>
<a href="http://crbug.com/151927" target="_blank">http://crbug.com/151927</a>) Most look like bugs, but this one doesn't<br>
really:<br>
<br>
/usr/local/google/work/chrome/src/v8/src/utils.h:977:20: warning:<br>
comparison of constant 32 with expression of type<br>
'v8::internal::AstPropertiesFlag' is always true<br>
[-Wtautological-constant-out-of-range-compare]<br>
    ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));<br>
    ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
<br>
The code, with context, is available at [1]. This is in a class<br>
template, and 'element' has the type of a template parameter, so<br>
depending on what type the template is instantiated with, the<br>
comparison might be tautological or not. Perhaps the warning shouldn't<br>
fire for expressions that depend on template parameters?<br>
<br>
Thanks,<br>
Hans<br>
<br>
 1. <a href="http://code.google.com/searchframe#W9JxUuHYyMg/trunk/src/utils.h&l=976" target="_blank">code.google.com/searchframe#W9JxUuHYyMg/trunk/src/utils.h&l=976</a><br></blockquote></div><br>I concur with you on this. I had the case of tautological comparisons several times (with gcc) in template functions and this is annoying. If I remember correctly I cheated by casting the small value (here "element") to a suitable big integer prior to the comparison, but it's annoying (especially if ones has to switch between signed and unsigned versions of the big integer...).<br>
<br>-- Matthieu.<br>