On 9/26/14 9:26 PM, H. S. Teoh via Digitalmars-d wrote:
Not a bad start. Though I do note that *declaring* an unsafe union
(according to the above definitions) is currently allowed in @safe code
by the compiler, but attempts to access a union member that overlaps
with a pointer is rejected.
It makes sense that you can declare unsafe unions, because a declaration
itself isn't @safe, it's only code that is.
But my attempts to test this haven't yielded an error.
e.g.:
class Foo
{
union {
private int _a;
public int *a;
}
void setA(int x) @safe { *a = x;}
}
no complaints...
> IOW, the compiler doesn't refuse definitions
of potentially unsafe unions, as long as you don't actually try to do
something unsafe with them. That might make unions more useful (they can
be passed around in @safe code as long as certain operations are
avoided), but probably also trickier to implement correctly.
I think it *should* be that way, but I'm not convinced it is yet.
-Steve