[Issue 8773] New: [CTFE] foreach ref element doesn't work well at compile time.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Oct 7 01:30:55 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8773

           Summary: [CTFE] foreach ref element doesn't work well at
                    compile time.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: zan77137 at nifty.com


--- Comment #0 from SHOO <zan77137 at nifty.com> 2012-10-07 01:18:56 PDT ---
This code doesn't work well:
--------------------------------------
import std.stdio;

void foo(ref string[] data)
{
    foreach (ref e; data)
    {
        e = e ~ "!";
    }
}
string[] bar(string[] data)
{
    foo(data);
    return data;
}
void main()
{
    enum data = ["a", "bcde", "abcde"];
    enum resCt = bar(data);
    auto resRt = bar(data);
    writeln(resCt); // NG: ["a", "bcde", "abcde"]
    writeln(resRt); // OK: ["a!", "bcde!", "abcde!"]
    assert(resCt == resRt); // NG
}
-------------------------------------

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


More information about the Digitalmars-d-bugs mailing list