www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15672] New: Casting from void[] to T[] is erroneously

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

          Issue ID: 15672
           Summary: Casting from void[] to T[] is erroneously considered
                     safe
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dhasenan gmail.com

Example:
---
void main()  safe {
    int*[] a = [new int];
    void[] b = cast(void[])a;
    size_t[] c = cast(size_t[])b;
    c[0] = 0;
    *(a[0]) = 0;  // Segmentation fault
}
---

If it were only allowed to cast to immutable(T)[] from void[], that would be
safe.

Thanks to iakh for the test case.

--
Feb 10 2016