is private broken?

Jonathan Marler johnnymarler at gmail.com
Tue Oct 10 19:20:19 UTC 2017


On windows I was able to compile the following using both 
dmd.2.075.1 and dmd.2.076.1

 From what I understand, you shouldn't be able to access private 
fields/methods like this...am I missing something?  I find it 
hard to believe that a bug of this magnitudue could have been 
introduced and not been noticed for so long. Does this compile on 
other people's systems as well?

import std.stdio;
struct SomeStruct
{
     private int privateValue;
     private void privateFunction()
     {
     }
}
class SomeClass
{
     private int privateValue;
     private void privateFunction()
     {
     }
}
void main()
{
     auto someStruct = SomeStruct(42);
     writefln("someStruct.privateValue = %s", 
someStruct.privateValue);
     someStruct.privateFunction();

     auto someStructRef = new SomeStruct(42);
     writefln("someStructRef.privateValue = %s", 
someStructRef.privateValue);
     someStruct.privateFunction();

     auto someClass = new SomeClass();
     writefln("someClass.privateValue = %s", 
someClass.privateValue);
     someClass.privateFunction();
}


More information about the Digitalmars-d mailing list