www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 256] New: Implicit unsigned to signed doesn't always work.

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=256

           Summary: Implicit unsigned to signed doesn't always work.
           Product: D
           Version: 0.162
          Platform: PC
               URL: http://www.digitalmars.com/d/type.html
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: minor
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jpelcis gmail.com


According to the D spec, a signed type can be implicitly converted to its
equivalent unsigned type (see Types, Implicit Conversions).  Testing shows that
that isn't always true.

---------------------------

void main () {
        ubyte byteValue = cast(byte)-1;
        ushort shortValue = cast(short)-1;
        uint intValue = cast(int)-1;
        ulong longValue = cast(long)-1;
}

---------------------------

C:\programs>dmd test.d
test.d(2): cannot implicitly convert expression (cast(byte)-1) of type byte to
u
byte
test.d(3): cannot implicitly convert expression (cast(short)-1) of type short
to
 ushort

---------------------------

As you can see, only the uint and ulong parts can be successfully compiled. 
Casting explicitly to unsigned type still works.


-- 
Jul 17 2006
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=256


bugzilla digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED





Fixed DMD 0.164 (revised documentation to reflect intended behavior)


-- 
Aug 11 2006