[Issue 19326] New: .tupleof sidesteps protection attributes

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Oct 22 14:08:26 UTC 2018


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 at puremagic.com
          Reporter: simen.kjaras at 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

--


More information about the Digitalmars-d-bugs mailing list