https://issues.dlang.org/show_bug.cgi?id=22045

          Issue ID: 22045
           Summary: Assignment of pointers in union should be @safe, only
                    pointers access are @system
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: [email protected]
          Reporter: [email protected]

This code should successfully compile:

void main() @safe
{
    union Foo {
        int a;
        int* b;
    }
        Foo foo;
    foo.b = new int;
}

Nothing unsafe here.

It worked in DMD 2.065.0 to 2.071.2.

More examples:

void main() @safe
{
    union Foo {
        int a;
        int* b;
    }
        Foo foo;
    int* c = (foo.b = new int);
}

This, however shouldn't compile:

void main() @safe
{
    union Foo {
        int a;
        int* b;
    }
        Foo foo;
    int* c = foo.b;
}

--

Reply via email to