https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120359

            Bug ID: 120359
           Summary: -Wtype-limits misses a warning when comparing enums
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: diagnostic, testsuite-fail, xfail
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
                CC: dnovillo at gcc dot gnu.org, gcc-bugs at gcc dot gnu.org,
                    manu at gcc dot gnu.org, pinskia at gcc dot gnu.org
        Depends on: 33738
            Blocks: 89129, 33702
  Target Milestone: ---

+++ This bug was initially created as a clone of Bug #33738 +++
This testcase (g++.dg/warn/pr33738.C) was xfailed at r7-3163-g973625a04b3d93
and then the code which did the warning was removed at r13-4277-gca0be1bbedd637
.

The original bug report follows:
This was found on GCC 4.2.1.  In this test case, VRP quietly folds a comparison
between an enum type and a constant value that the enum type can never take.
With -Wtype-limits, this should give the warning:

comparison always false due to limited range of data type

extern void link_error (void);

enum Alpha {
 ZERO = 0, ONE, TWO, THREE
};

Alpha a2;

int m1 = -1;
int GetM1() {
 return m1;
}

int main() {
 a2 = static_cast<Alpha>(GetM1());
 if (a2 == -1) {                   <-- VRP should warn when folding this.
    link_error ();
 }
 return 0;
}

This is not warned by the front end because we promote -1 to the same type as
a2.  But during VRP, we *do* fold the predicate, so warning when -Wtype-limits
is given in this case would be a good QOI feature.

I have a patch in the works to make VRP warn when it linearizes this predicate.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33702
[Bug 33702] [meta-bug] GCC 4.4 pending patches
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33738
[Bug 33738] -Wtype-limits misses a warning when comparing enums
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89129
[Bug 89129] [meta-bug] bogus/missing -Wtype-limits warnings

Reply via email to