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);
}
-----------------------------------