[Issue 1620] New: std.conv.to fails for integer unsigned->signed	conversion
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Sun Oct 28 10:00:59 PDT 2007
    
    
  
http://d.puremagic.com/issues/show_bug.cgi?id=1620
           Summary: std.conv.to fails for integer unsigned->signed
                    conversion
           Product: D
           Version: 2.006
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: i.kasiuk at gmx.de
A conversion like to!(int)(123u) fails, producing the following error at
runtime:
Error: Error: overflow Conversion underflow
Here is the code from conv.d which does the check:
  static const
      sSmallest = isFloatingPoint!(S) ? -S.max : S.min,
      tSmallest = isFloatingPoint!(T) ? -T.max : T.min;
  static if (sSmallest < tSmallest) {
    // possible underflow
    if (value < tSmallest) conv_overflow("Conversion underflow");
  }
  ...
This apparently doesn't work as intended because of the implicit conversions
happening when the values are compared.
Actually, why does the compiler silently do an implicit type conversion here? I
think this is a bit unfortunate.
-- 
    
    
More information about the Digitalmars-d-bugs
mailing list