D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1161 - [module] Access to private static members is allowed from other module.
Summary: [module] Access to private static members is allowed from other module.
Status: RESOLVED WONTFIX
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 2573 3108
  Show dependency treegraph
 
Reported: 2007-04-18 04:03 UTC by Marcin Kuszczak
Modified: 2016-10-14 03:13 UTC (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Marcin Kuszczak 2007-04-18 04:03:14 UTC
-----------
module static_a;
import static_b;
void main() {
    Test.counter=5;
}
-----------
module static_b;
class Test {
private:
    static int counter=0;
}
Comment 1 Tomas Lindquist Olsen 2008-05-04 21:10:29 UTC
Adding the following line to expressions.c(VarExp::semantic) catches it:

// check access to VarDeclaration
accessCheck(loc, sc, NULL, var);
Comment 2 Tomas Lindquist Olsen 2008-05-06 22:48:39 UTC
I've compiled several tango modules with this fix in place and it has already exposed two bugs in tango and no false positives so far.

;)
Comment 3 Tomas Lindquist Olsen 2008-09-27 09:14:36 UTC
This fix has been in place in LLVMDC for a long time, the change is trivial, it's not yet produced any false positives, just found bugs ... could we please get this into DMD ?
Comment 4 Matti Niemenmaa 2008-09-27 11:15:07 UTC
Severity doesn't mean how easy an issue is to fix. I set it back to "normal" and added the "patch" keyword instead.

As an aside, does that patch also fix Issue 313? What about Issue 314?
Comment 5 Christian Kamm 2008-09-30 00:37:41 UTC
(In reply to comment #4)
> As an aside, does that patch also fix Issue 313? What about Issue 314?

No it doesn't, but 314 has a patch that could be adapted to fix both. I didn't apply it to LLVMDC since it'd break compatibility to DMD in a fairly major way. On the other hand, it *is* a bug; I'll look at it again.
Comment 6 Tomas Lindquist Olsen 2008-12-10 06:58:17 UTC
The fix I proposed is indeed broken (or accessCheck is), it causes protection problems when instantiating imported templates passing private variables as alias template parameters. I've removed it from LDC again. Removing patch keyword
Comment 7 Kenji Hara 2012-12-18 21:38:56 UTC
Partially fixed in issue 5385.
Comment 8 Andrej Mitrovic 2012-12-19 02:25:48 UTC
(In reply to comment #7)
> Partially fixed in issue 5385.

Which testcases did I miss?
Comment 9 hsteoh 2014-07-19 01:25:16 UTC
Seems to have been fixed in git HEAD (D2): the compiler now says, for the original test case:

static_a.d(4): Error: class static_b.Test member counter is not accessible

Removing D2 tag.
Comment 10 Walter Bright 2016-10-14 03:13:12 UTC
As this is fixed in D2, and broke existing code while doing it. Any use of D1 is for legacy compatibility and not breaking things, so there seems no reason to fix this for D1.