June 30, 2013 [Issue 10512] New: Reinterpret-casting struct fields as another struct should be @safe | ||||
---|---|---|---|---|
| ||||
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@puremagic.com ReportedBy: tommitissari@hotmail.com --- Comment #0 from Tommi <tommitissari@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: ------- |
June 30, 2013 [Issue 10512] Reinterpret-casting struct fields as another struct should be @safe | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tommi | http://d.puremagic.com/issues/show_bug.cgi?id=10512 Maxim Fomin <maxim@maxim-fomin.ru> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |maxim@maxim-fomin.ru --- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-06-30 11:40:49 PDT --- These structs may come from different implementations with different alignments. In general case structs may include other aggregate types where situation may be complicated. D has unions for such tricks (you are better with placing long l in last place). In my opinion this is wontfix. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation