digitalmars.D.bugs - [Issue 24394] New: mutable array can be returned as string
- d-bugmail puremagic.com (34/34) Feb 13 https://issues.dlang.org/show_bug.cgi?id=24394
https://issues.dlang.org/show_bug.cgi?id=24394 Issue ID: 24394 Summary: mutable array can be returned as string Product: D Version: D2 Hardware: x86 OS: Windows Status: NEW Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: forestix nom.one Originally reported in the forum: https://forum.dlang.org/thread/gkoqjxixfiwftivjkxqp forum.dlang.org I'm now reporting it here, since more experienced D users seem to agree it's a bug. I was surprised to find that this code compiles with no complaints: safe: string test(ubyte[] arr) { import std.string; return arr.assumeUTF; // why does this compile? } void main() { import std.stdio; ubyte[] buf = ['g', 'o', 'o', 'd']; string dodgy = buf.test; // this string points to mutable data buf[] = ['b', 'a', 'd', '!']; writeln(typeof(dodgy).stringof); writeln(dodgy); } --
Feb 13