www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19916] New: union member access should be un- safe

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: nobody puremagic.com
          Reporter: turkeyman gmail.com

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
}

--
May 28 2019