MISRA Discussion Forums
Underlying type's implicit conversion of the shift operators - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.5 Expressions (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=134)
+---- Thread: Underlying type's implicit conversion of the shift operators (/showthread.php?tid=1497)



Underlying type's implicit conversion of the shift operators - chill - 19-07-2019

Is there a implicit conversion in shift expressions?

Quote:The underlying type of the result is the underlying type of the shift-expression.

[code]
int8_t i8;
uint8_t u8;
uint32_t u32;
int32_t i32;

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

u32


Re: Underlying type's implicit conversion of the shift operators - misra cpp - 16-10-2019

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.