D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3288 - conv.d : using to with const int or long fails to compile.
Summary: conv.d : using to with const int or long fails to compile.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 regression
Assignee: No Owner
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2009-09-03 09:55 UTC by Rob Jacques
Modified: 2015-06-09 01:26 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Rob Jacques 2009-09-03 09:55:30 UTC
The to!string conversion template doesn't handle const int or long values i.e.

const h  = 6;
string s = to!string(h); // Error

This seems to effect text, but not writeln.

Patch:

change 
u /= 10;
to
u = u / 10;

inside 
/// Signed values ($(D int) and $(D long)).
T to(T, S)(S value)
if (staticIndexOf!(Unqual!S, int, long) >= 0 && isSomeString!T)

Line# 2580 in dmd 2.032
Comment 1 Rob Jacques 2009-09-03 10:04:55 UTC
Better patch:

changing
auto u = -cast(Unsigned!S) value;
to
auto u = -cast(Unsigned!(typeof(value+0))) value;

on line 2575;
Comment 2 HOSOKAWA Kenchi 2009-09-04 09:41:44 UTC
(In reply to comment #1)
(maybe) more better patch:

2575:    auto u = -cast(Unqual!(Unsigned!S)) value;

Just you need is removing qualifier from S.
std.traits.Unqual is the best way to do it.
Comment 3 Andrei Alexandrescu 2009-09-04 10:42:04 UTC
(In reply to comment #2)
> (In reply to comment #1)
> (maybe) more better patch:
> 
> 2575:    auto u = -cast(Unqual!(Unsigned!S)) value;
> 
> Just you need is removing qualifier from S.
> std.traits.Unqual is the best way to do it.

Fixed as you suggested, coming with 2.033. Thanks!
Comment 4 Walter Bright 2009-10-06 02:22:05 UTC
Fixed dmd 2.033