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

           Summary: CTFE: Appending dchar to empty string creates invalid
                    string.
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: yebbl...@gmail.com


--- Comment #0 from yebblies <yebbl...@gmail.com> 2010-06-25 02:01:40 PDT ---
With dmd2.047 the following code will create a string which is actually invalid
utf-32.
The problem goes away if you start with a non-empty string.
This can occur easily when appending is used in conjunction with the new string
front() and back() functions that return dchar.

test case:


import std.stdio;

string get()
{
    string s;
    dchar c = 'D';

    s ~= c;
    s ~= c;

    return s;
}

void main()
{
    enum s = get(); // Call 'get' with ctfe
    writeln('"', s, '"'); // outputs "D "

    auto p = (s.ptr); // take pointer to defeat bounds checking
    auto s2 = p[0..8];
    writeln('"', s2, '"'); // outputs "D   D   "

    auto s3 = get(); // At compile time, this works as expected
    writeln('"', s3, '"'); // outputs "DD"
}

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

Reply via email to