www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22045] New: Assignment of pointers in union should be safe,

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

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;
}

--
Jun 19