[Mono-devel-list] Warnings building mcs/mcs

Jonathan Gilbert 2a5gjx302 at sneakemail.com
Mon Jan 5 00:12:15 EST 2004

At 03:23 PM 04/01/2004 +0900, Nick Drochak ndrochak-at-gol.com |mono-list
subscription| wrote:
>Hi. Here's a simple patch for eliminating a couple of warnings in mcs/mcs
>(sorry about the formatting).  OK to commit this?
>Also, there are two more warnings I'd like to get rid of, but not sure how.
>The are:
>ecore.cs(2177,24): warning CS0659: 'Mono.CSharp.TypeExpr' overrides
>Object.Equals(object o) but does not override
>        Object.GetHashCode()

This warning means exactly what it says: that type overrides the "Equals"
method, but it allows the base type to implement "GetHashCode". You can
squish this warning by overriding GetHashCode() from class TypeExpr as
well. Something like the following would not affect behaviour at all, but
would be a (very minor) performance hit if TypeExpr's GetHashCode method is
ever called (assuming the JIT doesn't optimize the entire method body into
a simple vtable change):

public abstract class TypeExpr : Expression {
  public override int GetHashCode() {
    return base.GetHashCode();

>cfold.cs(271,27): warning CS0675: Bitwise-or operator used on a
>sign-extended operand; consider casting to a smaller
>        unsigned type first

I can't locate the code which this refers to (in that source file, current
anoncvs, I only see bitwise-ands), but the meaning of this warning is that
one of the operands to a bitwise-or operation is signed and is shorter than
the width of the bit field. This is important in the case where the bit
field is wider than that argument; if that shorter argument's high bit is
set, then that argument will be sign-extended, which will set all the bits
in the bit field higher than that. For example, say you have a 32-bit bit
field, and through some bad planning, you want to set the 15th bit using a
signed short variable:

  uint bitfield = 0;
  short bit15 = unchecked((short)0x8000);

  bitfield |= bit15;

After this, bitfield's value is in fact not 0x00008000 but 0xFFFF8000. As
the warning indicates, it can be squelched by casting the shorter argument
to the corresponding unsigned type:

  bitfield |= (ushort)bit15;

This will set bitfield to the expected value of 0x00008000.

Good luck :-)


More information about the Mono-devel-list mailing list