[Issue 7597] New: Statically disallow a init() method in structs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Feb 26 16:19:42 PST 2012


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 at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2012-02-26 16:19:31 PST ---
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: -------


More information about the Digitalmars-d-bugs mailing list