www.digitalmars.com         C & C++   DMDScript  

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

http://d.puremagic.com/issues/show_bug.cgi?id=7597

           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
Foo*
}


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:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.learn&article_id=32944

------------------

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