The following code compiles without warning:
std::uint16_t a = 12;
std::uint16_t b = a & 0x003f;
However, performing a bit shift along with the bitwise and leads to an 'implicit cast warning':
std::uint16_t b = (a & 0x003f) << 10; // Warning generated.
Both gcc and clang complain that there is an implicit conversion from int
to uint16_t
, yet I fail to see why introducing the bit shift would cause the right hand expression to suddenly evaluate to an int
.
EDIT: For clang, I compiled with the -std=c++14 -Weverything
flags; for gcc, I compiled with the -std=c++14 -Wall -Wconversion
flags.