I have a piece of code which assigns an 8-bit unsigned int (std::uint8_t
) to a 32-bit unsigned int (std::uint32_t
):
std::uint32_t a{0};
std::uint8_t b{1};
a = b << 16;
When I try to compile this with -Werror -Wsign-conversion -fsanitize=undefined
, it fails with a sign-conversion error:
<source>:9:11: error: conversion to 'uint32_t' {aka 'unsigned int'} from 'int' may change the sign of the result [-Werror=sign-conversion]
Why is this? What is being promoted to int
?