On Sunday, November 04, 2012 08:59:10 Andrei Alexandrescu wrote: > Slicing of static arrays is unsafe only if they're stack-allocated and > the slice is subsequently escaped.
If we want to make it so that slicing a static array is @safe when the compiler can determine for sure that the slice isn't escaping, then fine, but in general, it can't do that. And taking the address of a local variable is already considered @system regardless of what you do with it. Taking the slice of a static array is really no different from taking the address of a local variable. It's just that it has a length along with the address. So, it would be completely in line with how taking the address of a local variable is treated to make taking the slice of a static array which is a local variable @system. Regardless, the point is that there is a major hole at this point with how slicing static arrays is always considered @safe. Nothing which the compiler can't guarantee is @safe should be considered @safe. So, even if we treat slicing static arrays as @safe in some cases, they need to be cases where the compiler is able to prove that it's safe. - Jonathan M Davis
