c++/7536: C++ front end does not warn of promotion of negative ints to unsigneds

Wolfgang Bangerth bangerth@ticam.utexas.edu
Thu Nov 21 21:06:00 GMT 2002


> |     double dostuff(int i)
> |     {
> |       const unsigned cx = 10;
> |       return i-cx;
> |     }
> 
> Here is how things happen (as per the standard):
> 
>   1) since cx is unsigned, "i" is converted to unsigned int
>      before the operation, which yeilds an unsigned value.  Note that,
>      the above may be written equivalently explicilty as 
>        (unsigned)i + (unsigned)-10
> 
>   2) the result is converted to double in the return.
> 
> That is, the destination type does not "hijack" into the
> sub-expressions.

That was clear. The question I was unsure about was whether the expression 
is converted to the type of the left, or of the right operand, or in the 
case of differing signedness, to a signed integer.

Given your explanation, should we expect a warning? (On this depends 
whether I re-classify the report as "change-request" or whether I close 
it).

Thanks for your explanation
  Wolfgang

-------------------------------------------------------------------------
Wolfgang Bangerth              email:           bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth




More information about the Gcc-bugs mailing list