Underlying type's implicit conversion of the shift operators

Moderators: david ward, misra cpp

Post Reply
chill
Posts: 1
Joined: Fri Jul 19, 2019 11:32 am
Company: SourceBrella

Underlying type's implicit conversion of the shift operators

Post by chill » Fri Jul 19, 2019 12:49 pm

Is there a implicit conversion in shift expressions?
The underlying type of the result is the underlying type of the shift-expression.

Code: Select all

int8_t i8;
uint8_t u8;
uint32_t u32;
int32_t i32;

u32 + i8; // i8 -> u32
u32 += i8; // i8 -> u32

u32 << i8; // ?
i8 << u32; // ?

u32 <<= i8; // i8 -> ?
i8 <<= u32; // ?


misra cpp
Posts: 148
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Underlying type's implicit conversion of the shift operators

Post by misra cpp » Wed Oct 16, 2019 12:05 pm

The first two are compliant, as they are performed as u32.

The four shift operators are compliant for this rule as they have the underlying type of the left argument, but may run into the rule about not shifting more than the length of the left operand (5-8-1), and 5-0-21 bans shifting of signed values.
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.5 Expressions (C++)”