D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11234 - Address of private method from another module can be taken
Summary: Address of private method from another module can be taken
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P3 normal
Assignee: No Owner
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2013-10-12 12:20 UTC by rswhite4
Modified: 2024-12-13 18:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description rswhite4 2013-10-12 12:20:03 UTC
A.d:
----
import B;

class Foo {
public:
	void call(Bar b) {
		void delegate(int) dg = &b.test;
		dg(42);
	}
}

void main() {
	Bar b = new Bar();
	Foo f = new Foo();
	f.call(b);
}
----

B.d:
----
import std.stdio;

class Bar {
private:
	void test(int id) {
		writeln("Bar called with ", id);
	}
}
----

Output: Bar called with 42
But should be rejected.
Comment 1 Andrej Mitrovic 2013-10-12 12:23:34 UTC
Reduced a little bit:

-----
module a;
import b;

void main()
{
    auto s = S();
    auto f = &s.f;  // no error
    f();  // no error

    auto sf = &S.sf;  // error
}
-----

-----
module b;
struct S
{
    private void f() { }
    private static void sf() { }
}
-----
Comment 2 rswhite4 2013-10-12 12:29:08 UTC
I'm unsure, but maybe we should also classify this as major because it breaks the protection?
Comment 3 dlangBugzillaToGithub 2024-12-13 18:12:37 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18694

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB