[Issue 2775] "private" ignored for templates

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Feb 15 20:16:47 PST 2016


https://issues.dlang.org/show_bug.cgi?id=2775

Simon Na. <eiderdaus at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eiderdaus at gmail.com

--- Comment #6 from Simon Na. <eiderdaus at gmail.com> ---
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.

--


More information about the Digitalmars-d-bugs mailing list