C++ Logo

SG12

Advanced search

Subject: Re: [ub] signed left shifts again
From: John Regehr (regehr_at_[hidden])
Date: 2013-11-13 17:26:08


> I have not seen the examples, but is it not the case that casting to unsigned
> before the shifts would have created defined behavior?

Yes, all of the undefined behaviors due to LHS of shifts would go away
with appropriate casts. I imagine that people just don't realize these
are necessary.

The bulk of the UBs were due to promotion of unsigned char to int. A
minority were due to variables that were declared as signed types in the
first place -- not a good idea, as you remarked earlier.

John


SG12 list run by sg12-owner@lists.isocpp.org