tmp1.d --- private struct TestStruct { int var; } --- tmp.d --- import tmp1; int main() { TestStruct s; s.var=0; return 0; } ---
Structs, unions, classes and variables can bypass the private attribute. Similar to BUG 313 and BUG 314, added dependancies. tmp1.d ------ private struct TestStruct { int var; } private union TestUnion { int var; } private class TestClass { int var; } private int var; tmp.d ----- import tmp1; void main() { TestStruct s; TestUnion u; auto c = new TestClass; s.var = var; // Fails s.var = a.var; // OK }
This is almost certainly a dup of BUG 1441. The same lack of privacy mechanism applies to all kinds of UDTs. It doesn't really have anything to do with BUG 313 or BUG 314.
What is 'a'? That line doesn't seem to have anything to say. But this code, compiled with the same tmp1.d, has something to say: ---------- import tmp1; void main() { TestStruct s; TestUnion u; auto c = new TestClass; auto sv = s.var; auto uv = u.var; auto cv = c.var; auto v = var; }
> tmp.d > ----- > import tmp1; > > void main() { > TestStruct s; > TestUnion u; > auto c = new TestClass; > s.var = var; // Fails > s.var = a.var; // OK // Typo. s.var = tmp1.var; //Compiles but shouldn't bug 314 > } Looks like a dup of bug 1440, my google-fu is weak.
^^it's actually my google-fu. Changing to spec bug. Spec should be clarified, how protection attributes work in this case.
Discussion taken to: "The great inapplicable attribute debate" digitalmars.D:87915 http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=87915
This is a bug in both D1 and D2, so I'm marking it as such. TestStruct shouldn't even be constructable outside of tmp1.d. The question of allowing you to access its member variables is secondary. It looks like the struct itself is being left as public, when it should be private. Now, it's still a bug if you can access its private member variables, but you shouldn't even be able to construct it in the first place.
It's not a spec bug. Private declarations should not be visible outside their module.
> It's not a spec bug. Private declarations should not be visible outside their > module. Do you mean not visible or not accessible? At present, private seems to work like C++ in that it's _always_ visible but not accessible. It's included in overload sets too.
I meant accessible.
Fix for D2: https://github.com/D-Programming-Language/dmd/pull/163
Peter's fixes from "Comment 11" is verified in dmd2.061 alpha, but looks wasn't merged into D1 branch, so tests still failed in dmd1.076 alpha. This record wss issued against D1 so status is unchanged.
Fixed in D2