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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
1 << bits is done as an int and then that is casted to size_t (which in this
case is unsigned long). That still does a sign extend.

>[left] Bit shifting is always unsigned operation.
No it is not, it might be zero filling and even shifting into the signed bit
might be undefined behavior depending on the C or C++ standard version you
compile to.


> Integer promotion rules say that unsigned type in expression must be promoted 
> to larger unsigned type if it can hold the result.

No it does not say that.
What it says is if the type is smaller than int, it will promote to int. NOTE
int here is signed.
That is:

unsigned short t = 1;
unsigned long tt = t << 2;
is really:
unsigned short t = 1;
int tmp = (int)t;
int tmp2 = tmp << 2;
unsigned long tt = (unsigned long)tmp2;

Reply via email to