https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91312

--- Comment #1 from Kostas Sotiropoulos <kosotiro at yahoo dot gr> ---
Hi,

When compiling the following code snippet with gcc 8.3.0 
with -Werror=conversion option:

#include <stdio.h>

#define MACRO 1

int main(void)
{
 unsigned char i;

 i += MACRO;
 return i;
}

the following warning which is treated as an error is reported:

test.c:3:15: error: conversion from ‘int’ to ‘unsigned char’ may change value
[-Werror=conversion]
 #define MACRO 1
               ^
test.c:9:7: note: in expansion of macro ‘MACRO’
  i += MACRO;
       ^~~~~
cc1: some warnings being treated as errors

Should this happen?

From what is described about -Wconversion under the following link:

https://gcc.gnu.org/onlinedocs/gcc-8.3.0/gcc.pdf I am not convinced
that even with casting the right hand of expression this problem should
still appear on this case. Please check this statement:

"Do not warn for explicit casts likeabs ((int) x)andui= (unsigned) -1, 
or if the value is not changed by the conversion like inabs(2.0)."

The only solution to this issue is to expand += and then cast to unsigned
char i.e. i = (unsigned char) (i + MACRO)? Should not we be more flexible
on cases of MACRO's even here that integer promotion takes place?

Thank you,
Kostas

Reply via email to