D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3333 - std.conv.to!(string, const int) error: cannot modify const
Summary: std.conv.to!(string, const int) error: cannot modify const
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All Linux
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-09-20 04:45 UTC by Lutger
Modified: 2015-06-09 01:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Lutger 2009-09-20 04:45:01 UTC
import std.conv;

void main()
{
    assert( to!string( cast(const int)1) == "1" );
}

errors:
src/phobos/std/conv.d(2580): Error: variable std.conv.to!(immutable(char)[],const(int)).to.u cannot modify const
src/phobos/std/conv.d(5): Error: template instance std.conv.to!(immutable(char) [],const(int)) error instantiating


Possible fix:

@@ -2570,11 +2570,11 @@
         return to!T(cast(Unsigned!(S)) value);

     alias Unqual!(ElementType!T) Char;
     Char[1 + S.sizeof * 3] buffer;

-    auto u = -cast(Unsigned!S) value;
+    Unqual!S u = -cast(Unsigned!S) value;
     uint ndigits = 1;
     while (u)
     {
         immutable c = cast(char)((u % 10) + '0');
         u /= 10;
Comment 1 Walter Bright 2009-10-06 02:22:49 UTC
Fixed dmd 2.033