www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7597] New: Statically disallow a init() method in structs


           Summary: Statically disallow a init() method in structs
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

This program comes from a reduction of a bug I've found:

struct Foo {
    void init() {}
void main() {
    Foo*[] foos;
    (*foos[0]).init(); // OK
    foos[0].init(); // Error: function expected before (), not null of type

I suggest to statically disallow the definition of a init() method in structs
(especially if they are a  property).

Some persons seem to agree.
See also the discussion:


Timon Gehr shows a case where defining a struct "init" method is useful, this
code compiles unless you de-comment the struct init. But maybe this is just a
bug in the implementation of  disable:

struct Foo {
     disable this();
    //  disable enum init = 0;
void main() {
    Foo f = Foo.init;

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 26 2012