Notice that I have tried this with several 32-bit native and cross GCC compilers including versions 3.2.2, 3.3, and 4.0.2.
In the test-case that follows, I get the warning in spite of the fact that the conditional is constant and "bitNumber" must always be less than 8 to execute the conditional. I discovered this feature while trying to write a generic C++ template where the "bitNumber" is a template parameter. I expected the constant conditional statement to be optimized with a "smart-enough" compiler. Since I always compile with -Werror, this warning is causing me a bit of grief. Note that the targets which I have tested all have 32-bit unsigned long integers. enum{ bitNumber = 15}; void test(unsigned long* p) { if(bitNumber < 8){ *p = (((unsigned long)0x01) << (bitNumber*4)); } } % gcc -c biterr.c biterr.c: In function `test': biterr.c:6: warning: left shift count >= width of type -- Summary: warning: left shift count >= width of type Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: mnmoran at bellsouth dot net http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26516