Bug 2775 – "private" ignored for templates

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-03-31T23:30:48Z
Last change time
2019-08-11T15:37:47Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Nick Sabalausky

Comments

Comment #0 by bus_dbugzilla — 2009-03-31T23:30:48Z
The following compiles successfully, but should result in some sort of "private template not accessible" or "no such template in current scope" error: // main.d import imported; void main() { char[] str = foo!(); } // imported.d private template foo() { const char[] foo = "foo"; }
Comment #1 by jakobovrum — 2010-01-09T20:34:03Z
(In reply to comment #0) > The following compiles successfully, but should result in some sort of "private > template not accessible" or "no such template in current scope" error: > > // main.d > import imported; > void main() > { > char[] str = foo!(); > } > > // imported.d > private template foo() > { > const char[] foo = "foo"; > } It happens for templated functions in DMD 2.039, as well. /* test.d */ module test; import std.stdio; class Class { private void foo(T...)(T args) { writeln("Hello, world!"); } } /* main.d */ module main; import test; int main() { scope a = new Class; a.foo(); return 0; }
Comment #2 by bugzilla — 2012-09-04T22:15:18Z
Comment #3 by issues.dlang — 2012-12-22T12:15:19Z
Hasn't this been fixed now?
Comment #4 by shachar — 2014-10-24T06:40:44Z
As of dmd v2.065 (5 and a half years after initial report) this problem is still open. Visibility limitation is touted, correctly, as a major language feature in "The D Programming Language". It is designed to prevent bugs and reduce development costs. As such, I took the liberty to raise the importance to "Major". Since the problem is happening to me on recent DMD, I changed the version to both D1 and D2. Hopefully, this will merit some attention to this bug.
Comment #5 by adrian — 2015-06-13T08:21:51Z
Still exists in 2.067.1.
Comment #6 by eiderdaus — 2016-02-16T04:16:47Z
In DMD 2.070, the bug still manifests for private template methods. It's fixed for static class functions, and for module-scope functions. Here's example code that errors out correctly: // foo.d import std.conv; private string func(T)(T t) { return t.to!string; } // main.d import std.stdio; import foo; void main() { writeln("hello world " ~ func(4)); } Error message, as expected: main.d(6): Error: module main template foo.func(T)(T t) is private main.d(6): Error: function foo.func!int.func is not accessible from module main However, if I make a class in foo.d and put the template inside, the code compiles, links, and calls the private function: // foo.d import std.conv; class A { private string func(T)(T t) { return t.to!string; } } // main.d import std.stdio; import foo; void main() { A a = new A(); writeln("hello world " ~ a.func(4)); } Expected instead: A privacy violation error, as in my first example code.
Comment #7 by pro.mathias.lang — 2019-08-11T15:37:47Z
The provided test cases now correctly error out.