This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/7536: C++ front end does not warn of promotion of negative ints to unsigneds
- From: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- To: Wolfgang Bangerth <bangerth at ticam dot utexas dot edu>
- Cc: gcc-bugs at gcc dot gnu dot org, <jss at ast dot cam dot ac dot uk>, <gcc-gnats at gcc dot gnu dot org>
- Date: 22 Nov 2002 04:24:31 +0100
- Subject: Re: c++/7536: C++ front end does not warn of promotion of negative ints to unsigneds
- Organization: Integrable Solutions
- References: <Pine.LNX.4.44.0211212058590.15656-100000@gandalf.ticam.utexas.edu>
Wolfgang Bangerth <bangerth@ticam.utexas.edu> writes:
| > | 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.
No matter who is on the right or on the left, if one is int an and the
other is unsigned then the int is converted to unsigned. The relevant
rule is dictated at 5/9
[...]
--- Otherwise, if either operand is unsigned, the other shall be
converted to unsigned.
| 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).
Well, I don't know what the C front-end does. I would suggest we do
whatever the does on this. If it does nothing, I'm not sure the
issue is frequent enought to warrant a warning.
-- Gaby