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

          Issue ID: 19667
           Summary: .offsetof cannot be used on non-public members of
                    aggregates in different modules
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nob...@puremagic.com
          Reporter: flybo...@gmail.com

Consider the following code:

module mod1;
public struct S {
    public int publicField;
    private int privateField;
}

-----
module mod2;
import mod1;

void main() {
    import std.conv : to;
    import std.stdio : writeln;
    writeln(to!string(S.publicField.offsetof)); //OK
    writeln(to!string(S.privateField.offsetof)); //Compiler error
}

This means that is impossible to correctly map the memory layout a given
aggregate from outside of the implementing module using only .offsetof.

I am aware that .tupleof can be used to bypass the protection checks, but using
.tupleof is a hack. Why can .tupleof bypass the checks, but not .offsetof?

--

Reply via email to