www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1620] New: std.conv.to fails for integer unsigned->signed conversion

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: i.kasiuk 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.


-- 
Oct 28 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1620






The bug is still present in version 2.011.


-- 
Mar 01 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1620


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|bugzilla digitalmars.com    |andrei metalanguage.com





I actually fixed this in my tree. The fix will be part of the next release.
Thanks!


-- 
Mar 01 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1620


andrei metalanguage.com changed:

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





Fixed in 2.012.


-- 
Mar 06 2008