[ub] ub due to left operand of shift

Jens Maurer Jens.Maurer at gmx.net
Sat Oct 26 07:53:11 CEST 2013


On 10/25/2013 10:10 PM, Jeffrey Yasskin wrote:
> On Fri, Oct 25, 2013 at 12:50 PM, Jens Maurer <Jens.Maurer at gmx.net> wrote:
>> If I'm reading 5p10 correctly, this should help (and is consistently
>> expressing intent):
>>
>> kappa[i] =
>>           (key[pos    ] << 24u) ^
>>           (key[pos + 1] << 16u) ^
>>           (key[pos + 2] <<  8u) ^
>>           (key[pos + 3]      );
>>
>> Jens
> 
> Nope: [expr.shift]p1 says, "The type of the result is that of the
> promoted left operand."

You're right, and thanks for explaining the funny conversion warnings
I get from recent gcc in circumstances like this.

Jens



More information about the ub mailing list