[Issue 10512] New: Reinterpret-casting struct fields as another struct should be @safe
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 30 11:08:15 PDT 2013
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: nobody at puremagic.com
ReportedBy: tommitissari at hotmail.com
--- Comment #0 from Tommi <tommitissari at hotmail.com> 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: -------
More information about the Digitalmars-d-bugs
mailing list