Bug 5954 – [CTFE] enum structs with ctor

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2011-05-07T16:31:00Z
Last change time
2011-06-17T00:29:38Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-05-07T16:31:20Z
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
Comment #1 by kennytm — 2011-05-24T08:12:57Z
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); } -----------------------------------
Comment #2 by clugdbug — 2011-05-30T16:55:58Z
Comment #3 by kennytm — 2011-06-17T00:29:38Z
*** Issue 6168 has been marked as a duplicate of this issue. ***