According to the C++ Standard
10 Many binary operators that expect operands of arithmetic or enumeration type cause conversions and yield result types in a similar way. The purpose is to yield a common type, which is also the type of the result. This pattern is called the usual arithmetic conversions,
The usual arithmetic conversion includes the integral promotion
1 A prvalue of an integer type other than bool, char16_t, char32_t, or wchar_t whose integer conversion rank (4.13) is less than the rank of int can be converted to a prvalue of type int if int can represent all the values of the source type; otherwise, the source prvalue can be converted to a prvalue of type unsigned int.
So in this expression
wat += 5;
that is equivalent to
wat = wat + 5;
wat
in the right side of the assignment is converted to type int
and the type of expression wat + 5
is int. As the range of values of type int
is greater than of type int8_t
the compiler issues the warning.
Also the message of the warning shows how to suppress the warning: [-Wconversion]