[cfe-commits] [PATCH] Improve -Wtautological-constant-out-of-range-compare

Richard Trieu rtrieu at google.com
Mon Nov 12 13:04:28 PST 2012


On Mon, Nov 12, 2012 at 11:22 AM, Eli Friedman <eli.friedman at gmail.com>wrote:

> Comments below.
>
> On Mon, Nov 12, 2012 at 9:46 AM, Richard Trieu <rtrieu at google.com> wrote:
> > Make -Wtautological-constant-out-of-range-compare checking take into
> account types and conversion between types.  The old version merely checked
> the bit widths, which allowed failed to catch a few cases, while warning on
> other safe comparisons.
> >
> > http://llvm-reviews.chandlerc.com/D113
> >
> > Files:
> >   test/Analysis/additive-folding.cpp
> >   test/SemaCXX/compare.cpp
> >   test/SemaCXX/warn-enum-compare.cpp
> >   lib/Sema/SemaChecking.cpp
>
> Index: test/SemaCXX/warn-enum-compare.cpp
> ===================================================================
> --- test/SemaCXX/warn-enum-compare.cpp
> +++ test/SemaCXX/warn-enum-compare.cpp
> @@ -39,8 +39,8 @@
>    while (b == c);
>    while (B1 == name1::B2);
>    while (B2 == name2::B1);
> -  while (x == AnonAA); // expected-warning {{comparison of constant
> 42 with expression of type 'Foo' is always false}}
> -  while (AnonBB == y); // expected-warning {{comparison of constant
> 45 with expression of type 'Bar' is always false}}
> +  while (x == AnonAA);
> +  while (AnonBB == y);
>    while (AnonAA == AnonAB);
>    while (AnonAB == AnonBA);
>    while (AnonBB == AnonAA);
>
> Why are you changing this warning?
>

Because it is valid to do:
x = (Foo)42;
which makes the condition true.

I'll be working on a patch to answer the rest of your comments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121112/190d5337/attachment.html>


More information about the cfe-commits mailing list