https://issues.dlang.org/show_bug.cgi?id=19916
Issue ID: 19916
Summary: union member access should be un-@safe
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: dmd
Assignee: [email protected]
Reporter: [email protected]
It should be invalid to access members of unions in @safe code.
It is necessary that code that interacts with unions implements the runtime
checks in a @trusted function.
struct S
{
union
{
int x;
float y;
}
bool whichOne;
}
void fun() @safe
{
S s;
int t = s.x; // COMPILE ERROR: NOT SAFE
s.x = 10; // COMPILE ERROR: NOT SAFE
}
--