digitalmars.D - Protection attributes on classes/interfaces
- John C (6/6) Sep 16 2005 Is protection going to be implemented for class and interface declaratio...
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (21/29) Sep 16 2005 From the D spec (http://www.digitalmars.com/d/attribute.html):
- John C (4/30) Sep 16 2005 I can't reproduce your linker error. D 0.131 allows me to new Foo, decla...
- Carlos Santander (4/41) Sep 16 2005 Maybe Jari-Matti just forgot to link test2.
- John C (3/44) Sep 17 2005 I've filed this issue under D.bugs.
Is protection going to be implemented for class and interface declarations? I was under the impression that it already was, but a quick test just now allowed me to create an instance of a class that is declared private in a separate module. The spec seems to indicate that protection only applies to module and class members -- any reason for classes and interfaces (or even structs) to be exempt from this?
Sep 16 2005
John C wrote:Is protection going to be implemented for class and interface declarations? I was under the impression that it already was, but a quick test just now allowed me to create an instance of a class that is declared private in a separate module. The spec seems to indicate that protection only applies to module and class members -- any reason for classes and interfaces (or even structs) to be exempt from this?From the D spec (http://www.digitalmars.com/d/attribute.html): "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. Private members cannot be overridden. Private module members are equivalent to static declarations in C programs." I tested this with the offsetof-bug example sent to d.bugs: [test2.d] private class Foo { int x; } [test.d] import test2; void main() { printf("%d",Foo.init.x.offsetof); // no error ?! Foo a = new Foo(); // linker error } --- DMD really seems to ignore private attributes when module members are not "directly" instantiated. One other thing is that there seems to be no compiler logic that could recognise the misuse of attributes. AFAIK it's the linker that complains as it cannot find a correct function signature.
Sep 16 2005
"Jari-Matti Mäkelä" <jmjmak invalid_utu.fi> wrote in message news:dge9vi$gs0$1 digitaldaemon.com...John C wrote:I can't reproduce your linker error. D 0.131 allows me to new Foo, declared privately in a separate module.Is protection going to be implemented for class and interface declarations? I was under the impression that it already was, but a quick test just now allowed me to create an instance of a class that is declared private in a separate module. The spec seems to indicate that protection only applies to module and class members -- any reason for classes and interfaces (or even structs) to be exempt from this?From the D spec (http://www.digitalmars.com/d/attribute.html): "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. Private members cannot be overridden. Private module members are equivalent to static declarations in C programs." I tested this with the offsetof-bug example sent to d.bugs: [test2.d] private class Foo { int x; } [test.d] import test2; void main() { printf("%d",Foo.init.x.offsetof); // no error ?! Foo a = new Foo(); // linker error }--- DMD really seems to ignore private attributes when module members are not "directly" instantiated. One other thing is that there seems to be no compiler logic that could recognise the misuse of attributes. AFAIK it's the linker that complains as it cannot find a correct function signature.
Sep 16 2005
John C escribió:"Jari-Matti Mäkelä" <jmjmak invalid_utu.fi> wrote in message news:dge9vi$gs0$1 digitaldaemon.com...Maybe Jari-Matti just forgot to link test2. -- Carlos Santander BernalJohn C wrote:I can't reproduce your linker error. D 0.131 allows me to new Foo, declared privately in a separate module.Is protection going to be implemented for class and interface declarations? I was under the impression that it already was, but a quick test just now allowed me to create an instance of a class that is declared private in a separate module. The spec seems to indicate that protection only applies to module and class members -- any reason for classes and interfaces (or even structs) to be exempt from this?From the D spec (http://www.digitalmars.com/d/attribute.html): "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. Private members cannot be overridden. Private module members are equivalent to static declarations in C programs." I tested this with the offsetof-bug example sent to d.bugs: [test2.d] private class Foo { int x; } [test.d] import test2; void main() { printf("%d",Foo.init.x.offsetof); // no error ?! Foo a = new Foo(); // linker error }
Sep 16 2005
"Carlos Santander" <csantander619 gmail.com> wrote in message news:dgfko1$1rab$1 digitaldaemon.com...John C escribió:I've filed this issue under D.bugs."Jari-Matti Mäkelä" <jmjmak invalid_utu.fi> wrote in message news:dge9vi$gs0$1 digitaldaemon.com...Maybe Jari-Matti just forgot to link test2. -- Carlos Santander BernalJohn C wrote:I can't reproduce your linker error. D 0.131 allows me to new Foo, declared privately in a separate module.Is protection going to be implemented for class and interface declarations? I was under the impression that it already was, but a quick test just now allowed me to create an instance of a class that is declared private in a separate module. The spec seems to indicate that protection only applies to module and class members -- any reason for classes and interfaces (or even structs) to be exempt from this?From the D spec (http://www.digitalmars.com/d/attribute.html): "Private means that only members of the enclosing class can access the member, or members and functions in the same module as the enclosing class. Private members cannot be overridden. Private module members are equivalent to static declarations in C programs." I tested this with the offsetof-bug example sent to d.bugs: [test2.d] private class Foo { int x; } [test.d] import test2; void main() { printf("%d",Foo.init.x.offsetof); // no error ?! Foo a = new Foo(); // linker error }
Sep 17 2005