[cfe-commits] r164143 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaChecking.cpp test/Analysis/additive-folding.cpp test/Sema/compare.c test/Sema/outof-range-constant-compare.c te

Matthieu Monrocq matthieu.monrocq at gmail.com
Tue Sep 25 11:30:04 PDT 2012


On Tue, Sep 25, 2012 at 5:29 PM, Hans Wennborg <hans at chromium.org> wrote:

> On Tue, Sep 18, 2012 at 6:37 PM, Fariborz Jahanian <fjahanian at apple.com>
> wrote:
> > Author: fjahanian
> > Date: Tue Sep 18 12:37:21 2012
> > New Revision: 164143
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=164143&view=rev
> > Log:
> > c: warn when an integer value comparison with an
> > integral expression have the obvious result.
> > Patch reviewed by John McCall off line.
> > // rdar://12202422
>
> This triggers a couple of warnings in Chromium. (We're tracking it at
> http://crbug.com/151927) Most look like bugs, but this one doesn't
> really:
>
> /usr/local/google/work/chrome/src/v8/src/utils.h:977:20: warning:
> comparison of constant 32 with expression of type
> 'v8::internal::AstPropertiesFlag' is always true
> [-Wtautological-constant-out-of-range-compare]
>     ASSERT(element < static_cast<int>(sizeof(T) * CHAR_BIT));
>     ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The code, with context, is available at [1]. This is in a class
> template, and 'element' has the type of a template parameter, so
> depending on what type the template is instantiated with, the
> comparison might be tautological or not. Perhaps the warning shouldn't
> fire for expressions that depend on template parameters?
>
> Thanks,
> Hans
>
>  1. code.google.com/searchframe#W9JxUuHYyMg/trunk/src/utils.h&l=976
>

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...).

-- Matthieu.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120925/adc713ab/attachment.html>


More information about the cfe-commits mailing list