https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93184
--- Comment #4 from ktkachov at gcc dot gnu.org --- (In reply to Wojciech Migda from comment #2) > Should there be at least a warning in case when the shift amount is a > compile-time known constant? In an ideal world yes. Howevever, most such warnings are done before any optimisations are done. To detect this case the compiler would need to inline mask into pub and do the constant propagation to figure out the bogus shift count. The compiler does warn about a more direct use of a negative shift count e.g.: static unsigned long long mask(const unsigned long long sz) { auto const rv = (unsigned long long)-1 >> (8 - 9) * 8; return rv; }