C++ Logo

sg12

Advanced search

Re: [ub] ub due to left operand of shift

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Sat, 26 Oct 2013 07:53:11 +0200
On 10/25/2013 10:10 PM, Jeffrey Yasskin wrote:
> On Fri, Oct 25, 2013 at 12:50 PM, Jens Maurer <Jens.Maurer_at_[hidden]> 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

Received on 2013-10-26 07:53:28