https://issues.dlang.org/show_bug.cgi?id=11176
Steven Schveighoffer <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #10 from Steven Schveighoffer <[email protected]> --- (In reply to Kenji Hara from comment #9) > One another way I can think is, array.ptr property would add a hidden check > `arr.length != 0` under @safe code, then returns `null` instead when the > length is 0. As someone who lives in the camp of "empty arrays and null arrays should be treated the same", I think this behavior wouldn't affect me. However, many significant people depend on this NOT being the case. Think of the pushback for the if(!arr) fix. To make the behavior different if you add a @safe tag may not affect them, but since the compiler can *infer* safety, this will be bad for anyone. Imagine you have template code not marked @safe, and you find a legitimate use for arr[$ .. $].ptr. The compiler may infer @safe, and then your code fails at runtime even though it would pass if not inferred @safe. In order to avoid such an issue, I think you have to just disallow ptr access in @safe code. That's the only thing that's checkable at compile-time, and will prevent a @safe inference. --
