Is this a bug in dmd 2.067 for struct initializers?
Ali Çehreli via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 18 23:46:49 PST 2015
On 02/18/2015 10:39 PM, stewarth wrote:
> This works under dmd 2066.1 but fails under dmd 2.067-b2.
I don't know whether it is a bug.
> struct B {
> A* a;
In any case, that must be immutable(A)*.
> }
>
> static immutable B[] someB = [{a:&someA[0]}, {a:&someA[1]}];
> I want it to initialize at runtime before main(). I don't
> actually want any CTFE stuff here.
Then you need 'static this()' (or 'shared static this()'):
static immutable B[] someB;
static this() {
someB = [ B(&someA[0]), B(&someA[1]) ];
}
Note that I could not use the named member syntax because in my case the
compiler cannot know what the right-hand side expression is. However, it
is still possible with a temporary where the type is explicit as in your
case:
static this() {
immutable B[] tmp = [ {a:&someA[0]}, {a:&someA[1]} ];
someB = tmp;
}
Ali
More information about the Digitalmars-d-learn
mailing list