This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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.
Attachment:
20080204-33738.diff.txt
Description: Text document
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |