Fix PR 33738
Diego Novillo
dnovillo@google.com
Tue Feb 5 04:13:00 GMT 2008
This bug is a failure to warn about an always-false predicate when
-Wtype-limits is used. Given:
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) { // { dg-warning "always false due" }
link_error ();
}
if (-1 == a2) { // { dg-warning "always false due" }
link_error ();
}
return 0;
}
The front end misses the warning because it explicitly upcasts both
operands when doing the checks. However, during VRP we discover that
a2 can never actually take the value -1, so the predicate is
discarded. With this patch, if -Wtype-limits is used, we also emit a
warning about it.
Bootstrapped and tested on x86_64, ppc64 and i686.
Diego.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 20080204-33738.diff.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20080205/68cd45db/attachment.txt>
More information about the Gcc-patches
mailing list