[Issue 627] New: Concatenation of strings to string arrays with ~ corrupts data

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Dec 2 11:52:15 PST 2006


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

           Summary: Concatenation of strings to string arrays with ~
                    corrupts data
           Product: D
           Version: 0.175
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: deewiant at gmail.com


void main() {
        // it works with integers
        int[] bar;
        assert ((bar ~ 1).length == bar.length + 1);

        // it works with integer arrays
        int[][] baz;
        assert ((baz ~ cast(int[])[1]).length == baz.length + 1);

        // but not with string arrays, be they char[], wchar[], or dchar[]
        char[][] foo;
        assert ((foo ~ cast(char[])"foo").length == foo.length + 1);

        // outputs 7303014 on my machine
        printf("%d\n", (foo ~ cast(char[])"foo")[0].length);

        // this works, though:
        assert ((foo ~ [cast(char[])"foo"]).length == foo.length + 1);

        // as does this:
        char[] qux;
        assert (([qux] ~ cast(char[])"foo").length == [qux].length + 1);

        // and it works with literals - presumably constant folded?
        assert (([cast(dchar[])"asdf"] ~ cast(dchar[])"foo").length ==
[cast(dchar[])"asdf"].length + 1);

        // ~= works
        char[][] quux;
        auto quuux = quux.dup;
        quuux ~= "foo";
        assert (quuux.length == quux.length + 1);
}


-- 




More information about the Digitalmars-d-bugs mailing list