www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20853] New: static array ptr cannot be used in safe code but

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 puremagic.com
          Reporter: destructionator 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.

--
May 21