I have a simple program. Notice that I use an unsigned fixed-width integer 1 byte in size.
#include
#include
[expr.unary.op]
The operand of
~shall have integral or unscoped enumeration type; the result is the one’s complement of its operand. Integral promotions are performed.
[expr.shift]
The shift operators
<<and>>group left-to-right. [...] The operands shall be of integral or unscoped enumeration type and integral promotions are performed.
What's the integral promotion of uint8_t (which is usually going to be unsigned_char behind the scenes)?
[conv.prom]
A prvalue of an integer type other than
bool,char16_t,char32_t, orwchar_twhose integer conversion rank (4.13) is less than the rank ofintcan be converted to a prvalue of typeintifintcan represent all the values of the source type; otherwise, the source prvalue can be converted to a prvalue of typeunsigned int.
So int, because all of the values of a uint8_t can be represented by int.
What is int(12) << 1 ? int(24).
What is ~int(12) ? int(-13).