www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19326] New: .tupleof sidesteps protection attributes

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

          Issue ID: 19326
           Summary: .tupleof sidesteps protection attributes
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: simen.kjaras gmail.com

module foo;
struct S {
    private int i;
}
----
module bar;
import foo;
 safe unittest {
    S s;
    // Fails: struct `foo.S` member i is not accessible
    s.i++;
    // Fails: struct `foo.S` member i is not accessible
    __traits(getMember, s, "i")++;
    // Compiles just fine:
    s.tupleof[0]++;
}

This breaks guarantees about what's accessible from other modules, and can be
used to break invariants relied on in  trusted code.

At the very least, this should not be  safe.

Related: issue 15371

--
Oct 22 2018