That happes also for signed bytes: Try to add
test<char>();
to your list.
The reason is the
integer promotion of both
s
and
u
(that is they are converted to
int
) in
cout << (s < u) << endl;
cout << (s + u) << endl << endl;
from
Implicit conversions - cppreference.com[
^]:
Integer promotions
Integer promotion is the implicit conversion of a value of any integer type with rank less or equal to rank of int or of a bit field of type _Bool, int, signed int, unsigned int, to the value of type int or unsigned int
If int can represent the entire range of values of the original type (or the range of values of the original bit field), the value is converted to type int. Otherwise the value is converted to unsigned int.
Integer promotions preserve the value, including the sign: