[Issue 7161] New: Passing string literal by ref changes its bounds forever

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 24 04:41:26 PST 2011


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

           Summary: Passing string literal by ref changes its bounds
                    forever
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: verylonglogin.reg at gmail.com


--- Comment #0 from Denis <verylonglogin.reg at gmail.com> 2011-12-24 15:41:24 MSK ---
---
import std.stdio;

void f(ref string s) {
    writeln(s);
    if(s.length)
        --s.length;
    else
        s = "def";
}

void g1() { f("abc"); }
void g2() { f("abc"); }

void main()
{
    g1();     // prints "abc"
    g2();     // prints "ab"
    f("abc"); // prints "a"
    f("abc"); // prints ""
    f("abc"); // prints "def"
}
---

-- 
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