[Issue 20853] New: static array ptr cannot be used in safe code but it should be allowed

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 21 19:22:33 UTC 2020


https://issues.dlang.org/show_bug.cgi?id=20853

          Issue ID: 20853
           Summary: static array ptr cannot be used in safe code but it
                    should be allowed
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: destructionator at gmail.com

@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.

--


More information about the Digitalmars-d-bugs mailing list