[Bug c/108580] gcc treats shifts as signed operation, does wrong promotion

postmaster at raasu dot org gcc-bugzilla@gcc.gnu.org
Sat Jan 28 08:04:25 GMT 2023


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108580

--- Comment #2 from postmaster at raasu dot org ---
If I try to shift to highest bit of signed type, the compiler will reject the
code and that is correct behaviour. The point here is that left-hand side of
the shift operation is by default same size as "int", as in 32 bits, which
means it can't be promoted to "int" again. 

This behaviour is same with gcc, clang and Visual C++, but Visual C++ correctly
gives warning that the code is ambiguous (exact message is "Arithmetic
overflow"), however it's also C++ compiler, which might validate the code with
C++ rules, not C.


More information about the Gcc-bugs mailing list