Bug 6844 – Reinterpret cast of static to dynamic array doesn't work in safe code
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2011-10-23T06:54:00Z
Last change time
2012-12-26T07:24:46Z
Keywords
rejects-valid
Assigned to
nobody
Creator
pszturmaj
Comments
Comment #0 by pszturmaj — 2011-10-23T06:54:44Z
void main() @safe
{
long[2] a;
auto b = cast(ubyte[])a; // error
auto c = cast(ubyte[])cast(long[])a; // works
}
main.d(4): Error: cast from long[2u] to ubyte[] not allowed in safe code
Without @safe mode there's no error.
Comment #1 by yebblies — 2012-12-26T07:24:46Z
Slicing a static array is equivalent to taking the address of a local variable, which is illegal in safed. The second case works due to bug 8838.
*** This issue has been marked as a duplicate of issue 8838 ***