[Issue 15672] New: Casting from void[] to T[] is erroneously considered @safe

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Feb 10 14:56:54 PST 2016


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

--


More information about the Digitalmars-d-bugs mailing list