19980824 bug in 3 user-defined operators
Reid M. Pinchback
reidmp@MIT.EDU
Thu Sep 3 06:34:00 GMT 1998
At 10:46 PM 9/2/98 -0300, you wrote:
>Reid M Pinchback <reidmp@MIT.EDU> writes:
>
>> ** egcs is doing promotion for three user-defined unary
>> ** operators (~,-,+)
>
>Nope, it is doing integral promotion of integral types, as required in
>[expr.unary.op]/6,7,9. The expression `+((short)1)', for example, has
>type `int', not `short'.
Ok, let's see if I understand what is going on. In the following code:
[stmt1] short x=1;
[stmt2] short y=+x;
we would have the following:
* in stmt1 the literal '1' is of type int, and the assignment to 'x'
would convert the literal to a short.
* in stmt2 'x' is a short, but '+x' is promoted to an int, and then
the assignment to 'y' causes the int value of '+x' to be converted
back to a short
correct? In other words, the integral promotion process is entirely
determined by the expression; what type the expression is being assigned
to isn't factored into the process. That means that in general when
using unary operators it is worth considering static_cast'ing the results
to ensure that the expressions have the type you think they should.
Sum days yah jus gotta luv dis langwage. :-)
====================================================
= Reid M. Pinchback =
= I/T Delivery, MIT =
= =
= Email: reidmp@mit.edu =
= URL: http://web.mit.edu/reidmp/www/home.html =
====================================================
More information about the Gcc-bugs
mailing list