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

--- Comment #7 from Kostas Sotiropoulos <kosotiro at yahoo dot gr> ---
(In reply to Andrew Pinski from comment #5)
> (In reply to Kostas Sotiropoulos from comment #4)
> > Any comments on my questions?
> 
> Yes go read the c standard about prompting to int here.

I had checked the standard from the following link:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf

I suppose that you mean the following two sections that cover our case:

6.5.16.2

A compound assignment of the form E1 op=E2 is equivalent to the simple
assignment expression E1 = E1 op (E2), except that the lvalue E1
is evaluated only once, and with respect  to  an  indeterminately-sequenced 
function  call,  the  operation  of  a  compound assignment  is  a  single 
evaluation. 

6.3.1.1 Boolean, characters, and integers

2 The following may be used in an expression wherever an int or unsigned int
may be used:

—  An object  or  expression  with  an  integer  type  (other  than int
or unsigned int) whose  integer  conversion  rank  is  less  than  or  
equal  to  the  rank  of int and unsigned int.

—  A bit-field of type _Bool, int, signed int, or unsigned int.

If an int can  represent  all  values  of  the  original  type  
(as  restricted  by  the  width,  for  a bit-field),  the  value  is  
converted  to  an int; otherwise,  it  is  converted  to  an unsigned int. 
These  are  called  the integer promotions. All  other  types  are  
unchanged  by  the integer promotions.

So considering the above two sections, if we even cast 
i += (unsigned char) MACRO then this would be equal to
i = i + (unsigned char) MACRO.

But, what if I want to avoid this warning then the only way to get 
rid of it is the following way?

i = (unsigned char) (i + MACRO).

But we will lose on code optimization be this way, do not we? Especially
when we are talking about Embedded Systems software.

Please note that the same code snippet passes through clang compiler (clang
version 3.8.1-24) without any warning when -Werror=conversion is used during
compilation. I suppose that even this compiler follows C standard. In my 
opinion such kind of warnings are false positives that should not be reported
from gcc compiler too.

Maybe a change of this kind on gcc compiler opens the Pandora's Box for other
things but someone should not avoid of defining MACROS and use them on compound
statements (+=, -=, *= etc) and sacrifice code optimization by expanding them.

Waiting for your comments.

Reply via email to