www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20655] New: attribute inference accepts unsafe union access

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

          Issue ID: 20655
           Summary: attribute inference accepts unsafe union access as
                     safe
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

As expected, accessing a union that contains pointers is not  safe:

----
union U
{
    string s;
    int x;
}
U u;

void f()  safe { auto s = u.s; } /* Error: field U.s cannot access pointers in
 safe code that overlap other fields */
----

But attribute inference accepts it as  safe:

----
union U
{
    string s;
    int x;
}
U u;

auto f1() { auto s = u.s; } /* Should be inferred as  system. */
void f2()() { auto s = u.s; } /* ditto */
void g()  safe
{
    void f3() { auto s = u.s; } /* ditto */
    f1(); /* Should be rejected with error "cannot call  system function". */
    f2(); /* ditto */
    f3(); /* ditto */
}
----

--
Mar 09