<div dir="ltr">I just managed to assign a const(char)[] to a string... caused crashes when the original memory disappeared.<div><br></div><div><div><div>inout(char)[] todstr(inout(char)* cstr) pure nothrow</div><div>{</div>
<div><span class="" style="white-space:pre"> </span>return cstr ? cstr[0 .. std.c.string.strlen(cstr)] : cstr[0 .. 0];</div><div>}</div><div><br></div><div>struct Data</div><div>{</div><div><span class="" style="white-space:pre"> </span>char buffer[256] = void;</div>
<div><span class="" style="white-space:pre"> </span>@property const(char)[] filename() const pure nothrow<span class="" style="white-space:pre"> </span>{ return todstr(buffer.ptr); }</div><div>}</div><div><br></div><div>struct MyThing</div>
<div>{</div><div><span class="" style="white-space:pre"> </span>private this(in Data* p)</div><div><span class="" style="white-space:pre"> </span>{</div><div><span class="" style="white-space:pre"> </span>filename = p.filename; // *** Uh oh! assigned a const(char)[] @property to a string! ***</div>
<div><span class="" style="white-space:pre"> </span>}</div><div><br></div><div><span class="" style="white-space:pre"> </span>string filename;</div><div>}</div></div></div><div><br></div><div>Surely that assignment shouldn't be legal? Shouldn't I need to idup?</div>
</div>