Bug 20853 – static array ptr cannot be used in safe code but it should be allowed

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-05-21T19:22:33Z
Last change time
2022-04-06T07:22:48Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Adam D. Ruppe

Comments

Comment #0 by destructionator — 2020-05-21T19:22:33Z
@safe void main() { int[2] i; int* a = i.ptr; } bug2.d(3): Error: i.ptr cannot be used in @safe code, use &i[0] instead There's no good reason to prohibit this because `i` has static length and thus it can be proven that .ptr is equivalent to &i[0] in all cases (unless length == 0 which can obviously be checked too) and cannot go out of bounds. Note that `i.ptr` when i has static length of 0 current compiles and should continue to compile with this change made if it is @system code.
Comment #1 by dlang-bot — 2022-04-03T17:58:11Z
@dkorpel created dlang/dmd pull request #13944 "Fix issue 20853 - static array ptr cannot be used in safe code but it…" fixing this issue: - Fix issue 20853 - static array ptr cannot be used in safe code but it should be allowed https://github.com/dlang/dmd/pull/13944
Comment #2 by dlang-bot — 2022-04-06T07:22:48Z
dlang/dmd pull request #13944 "Fix issue 20853 - static array ptr cannot be used in safe code but it…" was merged into master: - 40bc873a871a7c6891d9262da5931a0f9f59a60f by Dennis Korpel: Fix issue 20853 - static array ptr cannot be used in safe code but it should be allowed https://github.com/dlang/dmd/pull/13944