www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20941] New: __traits(getMember) should not allow safe code to

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

          Issue ID: 20941
           Summary: __traits(getMember) should not allow safe code to
                    access private fields
           Product: D
           Version: D2
          Hardware: x86
                OS: Mac OS X
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: andrei erdani.com

This is taken from DIP 1035:

struct S {
    private union {
        int x;
        int* y;
    }
    private int tag; // x if 0, y if 1
    // public  trusted interface follows
    void set(int rhs)  trusted {
        if (tag == 0) x = rhs;
        else *y = rhs;
    }
    ....
}

Allowing safe code to modify tag from  safe code, followed by calling set(),
results in unsafe code from safe functions.

This could be relaxed to restrict access only for types that have  trusted
functions.

--
Jun 17 2020