This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/33738] New: -Wtype-limits misses a warning when comparing enums
- From: "dnovillo at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Oct 2007 17:50:08 -0000
- Subject: [Bug c++/33738] New: -Wtype-limits misses a warning when comparing enums
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.
--
Summary: -Wtype-limits misses a warning when comparing enums
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: dnovillo at gcc dot gnu dot org
ReportedBy: dnovillo at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33738