Summary: CTFE: Appending dchar to empty string creates invalid
           Product: D
           Version: D2
          Platform: All
        OS/Version: Windows
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD

--- Comment #0 from yebblies <> 2010-06-25 02:01:40 PDT ---
With dmd2.047 the following code will create a string which is actually invalid
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:
------- You are receiving this mail because: -------

Reply via email to