[Issue 12252] New: struct default constructors that execute code.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Feb 25 06:56:42 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=12252

           Summary: struct default constructors that execute code.
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: remotion4d at gmail.com


--- Comment #0 from Remo <remotion4d at gmail.com> 2014-02-25 06:56:36 PST ---
extern(C)  int w_init(CWrapper *p);
extern(C) void w_free(CWrapper *p);

struct CWrapper {
    this() { //not possible
       w_init(&this);
    }
    ~this() {
       w_free(&this);
    }
}

void main(){
    S s; //should call w_init()
    S s1 = S(); //should call w_init() too
}


While porting C++ code to D2 it is some times necessary to do be able to mimic
C++ class/struct behavior. 

Using  this(int dummy){ ... } as a workaround compiles but does not work.
Other workarounds are complicated and error phone.

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


More information about the Digitalmars-d-bugs mailing list