This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Wolfgang Bangerth <bangerth@ticam.utexas.edu> writes:

| > |     Weird. I don't know what the standard says, though.
| > 
| > -10 is well-defined as unsigned integer :-)
| 
| :-) Sure. But does the standard say that in the return expression of
|     double dostuff(int i)
|     {
|       const unsigned cx = 10;
|       return i-cx;
|     }
| "i" is converted to unsigned, or "cx" to signed? Depending on that the 
| result is unexpected or not.

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.  Said differently, expressions are processed inner to
outer. 

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]