On Saturday, 11 January 2014 at 18:29:36 UTC, Manu wrote:
I just managed to assign a const(char)[] to a string... caused crashes when
the original memory disappeared.

inout(char)[] todstr(inout(char)* cstr) pure nothrow
{
return cstr ? cstr[0 .. std.c.string.strlen(cstr)] : cstr[0 .. 0];
}

struct Data
{
char buffer[256] = void;
@property const(char)[] filename() const pure nothrow { return
todstr(buffer.ptr); }
}

struct MyThing
{
private this(in Data* p)
{
filename = p.filename; // *** Uh oh! assigned a const(char)[] @property to
a string! ***
}

string filename;
}

Surely that assignment shouldn't be legal? Shouldn't I need to idup?

I don't know about the details of what is/isn't legal here, but the only reason the compiler accepts it is because filename is marked as pure.

Reply via email to