On Thursday, 16 March 2017 at 17:47:34 UTC, H. S. Teoh wrote:
Actually, the bug still exists even if you explicitly slice it:

        string x = func()[]; // still compiles, but shouldn't

I don't call that a bug, once it is explicitly done it means the programmer realized something is up and decided they are OK with it. Perhaps you want to pass it to a function that you know isn't going to hold the reference beyond the calling scope.

For some reason, slicing a static array return value is somehow OK, while slicing a local variable is rejected. Seems like the compiler is missing escaping ref checks for return values?

It's the uniqueness thing, see my last email (I probably was typing it at the same time you were typing this...)

This isn't an escape per se, `string x` is still a local variable.

immutable(char)[32] buffer;
string s = buffer[0 .. 16]; // sane and really useful optimization... just be careful not to escape it

Walter wants to expand the escape check so it automatically issues an error if you aren't careful enough, but the status quo is still usable - such code is not necessarily wrong, banning entirely it is a step backward, and programmers coming up the C tradition are used to watching lifetimes like that.

Reply via email to