www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5954] New: enum structs with ctor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5954

           Summary: enum structs with ctor
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



D2 code:


struct Foo {
    int x;
    this(int xx) {
        this.x = xx;
    }
}
void main() {
    enum f = Foo(10);
}


DMD 2.053beta is not able to compile it, and shows the errors:

test.d(8): Error: variable __ctmp3 cannot be read at compile time
test.d(8): Error: cannot evaluate __ctmp3.this(10) at compile time

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 07 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5954


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kennytm gmail.com
         OS/Version|Windows                     |All



A workaround is to construct it in a delegate.

-----------------------------------
struct Foo {
    int x;
    this(int xx) {
        this.x = xx * 6;
    }
}
void main() {
    enum f = { return Foo(10); }();
    static assert(f.x == 60);
}
-----------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 24 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5954


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



https://github.com/D-Programming-Language/dmd/commit/068ae6ec8f06060f52c6f0ae860476a7e10cb464

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 30 2011
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5954


kennytm gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |johann.macdonagh gmail.com



*** Issue 6168 has been marked as a duplicate of this issue. ***

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