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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jul 17 12:59:13 PDT 2006


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 at digitalmars.com
        ReportedBy: jpelcis at 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.


-- 




More information about the Digitalmars-d-bugs mailing list