Bug 1620 – std.conv.to fails for integer unsigned->signed conversion

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2007-10-28T12:00:00Z
Last change time
2015-06-09T01:14:19Z
Assigned to
andrei
Creator
i.kasiuk

Comments

Comment #0 by i.kasiuk — 2007-10-28T12:00:58Z
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.
Comment #1 by i.kasiuk — 2008-03-01T12:31:20Z
The bug is still present in version 2.011.
Comment #2 by andrei — 2008-03-01T17:40:36Z
I actually fixed this in my tree. The fix will be part of the next release. Thanks!
Comment #3 by andrei — 2008-03-07T00:38:27Z
Fixed in 2.012.