www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11863] New: std.conv.to!string(int/uint, radix) returns incorrect string

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863

           Summary: std.conv.to!string(int/uint, radix) returns incorrect
                    string
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: electrolysis.jp+d gmail.com


--- Comment #0 from e10s <electrolysis.jp+d gmail.com> 2014-01-04 03:38:46 JST
---
import std.conv, std.stdio;

void main(){
    /// int
    static assert(to!string(15, 10) == "15");  // success
    // assert(to!string(15, 10) == "15");  // failure
    assert(to!wstring(15, 10) == "15"w);  // success
    assert(to!dstring(15, 10) == "15"d);  // success
    writeln(to!string(15, 10));  // ??

    /// uint
    static assert(to!string(15u, 10) == "15");  // success
    // assert(to!string(15u, 10) == "15");  // failure
    assert(to!wstring(15u, 10) == "15"w);  // success
    assert(to!dstring(15u, 10) == "15"d);  // success
    writeln(to!string(15u, 10));  // ??

    /// long
    static assert(to!string(15L, 10) == "15");  // success
    assert(to!string(15L, 10) == "15");  // success
}


In the case of "(r)dmd foo.d", only to!string(int, radix) and
to!string(uint, radix) return "0" at run time with any radix
though "15" is returned when compiled with "-debug".

Environment: DMD 2.064.2 on Win7 SP1 32-bit

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2014
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com
          Component|Phobos                      |DMD
           Platform|x86                         |All
         OS/Version|Windows                     |All
           Severity|normal                      |regression


--- Comment #1 from monarchdodra gmail.com 2014-01-03 12:55:28 PST ---
I did some investigating, and the Phobos code is legit. Duplicating the
function, while leaving it where it is, does not reproduce the issue.
Furthermore, older versions of DMD do not reproduce this issue either.

It makes me think that ctfe instantiation is causing something weird later for
runtime.

I did a bissect, and hit this commit:

12bb9afb753ad2f2aef65550b960357c63854cbc is the first bad commit
commit 12bb9afb753ad2f2aef65550b960357c63854cbc
Author: Walter Bright <walter walterbright.com>
Date:   Wed Sep 11 14:33:14 2013 -0700

    fix Issue 10441 - Static libraries too big

:040000 040000 00ef3e43d4274d2e24514810353fead7bbcdaee9
313550fcc47de2b124d69f05bce5f94586bc2b01 M      src
:040000 040000 13dbdadb43e009e4e10041a161e1c825110f8028
7bcbc44d497d9056603b0863d781b894ff49b4ab M      test

Seems to be related. I think.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863



--- Comment #2 from Kenji Hara <k.hara.pg gmail.com> 2014-01-04 23:42:17 PST ---
Hmm, with "-allinst" switch, OP code runs successfully in Windows (Both -m32
and -m64).

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 04 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863



--- Comment #3 from monarchdodra gmail.com 2014-01-05 00:10:54 PST ---
(In reply to comment #2)
 Hmm, with "-allinst" switch, OP code runs successfully in Windows (Both -m32
 and -m64).

I *thought* I had tried that, but I must have gotten it wrong. I can confirm it works too for linux64. So... is this an actual bug? http://d.puremagic.com/issues/show_bug.cgi?id=11284 Seems to indicate the problem would come from a "build irregularity"? Does this mean there is a Phobos build irregularity? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863



--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2014-01-05 00:29:47 PST ---
(In reply to comment #2)
 Hmm, with "-allinst" switch, OP code runs successfully in Windows (Both -m32
 and -m64).

Instead of "-allinst", "-release" also suppresses the error. (In reply to comment #3)
 (In reply to comment #2)
 Hmm, with "-allinst" switch, OP code runs successfully in Windows (Both -m32
 and -m64).

I *thought* I had tried that, but I must have gotten it wrong. I can confirm it works too for linux64. So... is this an actual bug? http://d.puremagic.com/issues/show_bug.cgi?id=11284 Seems to indicate the problem would come from a "build irregularity"? Does this mean there is a Phobos build irregularity?

I'm not sure, but essentially I think "build irregularity" should not be there. If it exists, it is a fault of separate compilation feature. Current template instantiation strategy is fragile. Walter's implementation is often does not fully cover target cases when it is introduced... -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 05 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, wrong-code


--- Comment #5 from Kenji Hara <k.hara.pg gmail.com> 2014-01-06 22:12:15 PST ---
https://github.com/D-Programming-Language/dmd/pull/3069

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 06 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863



--- Comment #6 from github-bugzilla puremagic.com 2014-01-07 00:09:55 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/4c846a263a7e94c0966ef66a0e0fc4adda58c737
fix Issue 11863 - std.conv.to!string(int/uint, radix) returns incorrect string

https://github.com/D-Programming-Language/dmd/commit/6090f4599b4da0a642796c1d2655a26f0ce99b17
Merge pull request #3069 from 9rnsr/fix11863

[REG2.064] Issue 11863 - std.conv.to!string(int/uint, radix) returns incorrect
string

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 07 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11863


monarchdodra gmail.com changed:

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


--- Comment #7 from monarchdodra gmail.com 2014-01-07 00:48:34 PST ---
Resolved. Thanks a lot Kenji!

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 07 2014