www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15171] New: private/protected/package default construction


          Issue ID: 15171
           Summary: private/protected/package default construction
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: timon.gehr gmx.ch

As the unit of encapsulation is the module, it sometimes makes sense to manage
construction of a certain type on a by-module basis instead of a by-type basis.

Therefore, the following code should compile:

struct S{
    private this();
    private init;
    // (probably we also want  disable init, instead of
    // needing to hack around lack of it by hiding it
    // with a new declaration.)

Within the module, S should be default-constructible and S.init should be
accessible, but not outside the module.
This gives the author of the type full control over how S is constructed, but
it does not unduly constrain the author.

package and protected default construction are analogous. Probably, explicit
'public' should be allowed as well.

Oct 07 2015