On 04/23/2018 07:11 AM, Jason Vas Dias wrote:
I really do not think a '-Wpedantic -Wconversion' warning should be generated for the following code, but it is (with GCC 6.4.1 and 7.3.1 on RHEL-7.5 Linux) : $ echo ' typedef unsigned short U16_t; static void f(void) { U16_t a = 1; a-=1; }' > t.C;
g...@gcc.gnu.org dropped as inappropriate. Note that gcc-bugs is output from our bugzilla. Sending email here isn't very useful. If you want a bug fixed, you have to open a bug report in bugzilla. You can ask gcc questions on gcc help.
In the C language, operations on short and always performed as int, and then converted back to short. Subtracting one may generated a negative number, which converted to unsigned short will change its value. So the warning seems appropriate.
Note that -Wconversion means different things in different gcc versions. It current meaning is to warn for any implicit cast that may change a value. This is not very useful in general, and is not an option that I would recommend using by default. In old gcc versions, -Wconversion warned for code that had different meaning in K&R C and ISO C. That was useful, and some people used that option by default, but the option no longer does that.
You can silence the warning by adding an explicit cast. a = (U16_t) (a - 1); Jim