http://d.puremagic.com/issues/show_bug.cgi?id=10512
Summary: Reinterpret-casting struct fields as another struct
should be @safe
Product: D
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: DMD
AssignedTo: [email protected]
ReportedBy: [email protected]
--- Comment #0 from Tommi <[email protected]> 2013-06-30 11:08:15 PDT ---
The order and alignment of struct fields are statically known. Therefore the
compiler should be able to verify that the following code is memory safe and
let it compile:
@safe:
struct A
{
int i;
short s;
byte b;
}
struct B
{
long l;
int i;
short s;
byte b;
}
void main()
{
A a;
B b;
*(cast(A*) &b.i) = a; // [1]
}
[1] Error: cast from int* to A* not allowed in safe code
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------