D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3535 - struct constructors don't work in CTFE
Summary: struct constructors don't work in CTFE
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks: 4888
  Show dependency treegraph
 
Reported: 2009-11-20 15:49 UTC by Bill Baxter
Modified: 2015-06-09 01:27 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Bill Baxter 2009-11-20 15:49:09 UTC
struct Struct
{
    this(int _n) {
        n = _n; x = 5;
    }
    this(int _n, float _x) {
        n = _n; x = _x;
    }
    int n;
    float x;
}

enum A = Struct(1);  
enum A = Struct(1,2);


Both calls fail.  But if you /don't/ define any constructors then the second one would work.
Comment 1 Bill Baxter 2009-11-20 15:50:40 UTC
Additional note: static opCall does work with CTFE.
Comment 2 Don 2010-01-10 11:44:54 UTC
I have sent Walter a patch for this. This was much more difficult than you might expect.
Comment 3 Walter Bright 2010-01-11 22:02:24 UTC
Changeset 332
Comment 4 Walter Bright 2010-01-30 22:44:57 UTC
fixed dmd 2.040