[Issue 20655] New: attribute inference accepts unsafe union access as @safe
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon Mar  9 22:32:45 UTC 2020
    
    
  
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 at puremagic.com
          Reporter: ag0aep6g at 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 */
}
----
--
    
    
More information about the Digitalmars-d-bugs
mailing list