How to declare static compile-time assoc array inside struct?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Aug 17 19:58:03 UTC 2018


On Friday, August 17, 2018 9:59:18 AM MDT Steven Schveighoffer via 
Digitalmars-d-learn wrote:
> On 8/13/18 9:21 AM, Andrey wrote:
> > On Monday, 13 August 2018 at 11:53:06 UTC, rikki cattermole wrote:
> >> You must use a module constructor to initialize it.
> >
> > Tried this:
> > static this()
>
> `shared static this()`
>
> normal static this runs on every thread creation, and so cannot modify
> immutable data.

Well, it's not _supposed_ to be able to modify immutable data. It's a
long-standing bug that the compiler allows you to initialize immutable
variables in non-shared, static constructors, and if you do it, it's going
to reinitialize it in each thread, which is definitely not good, but for
whatever reason hasn't managed to be enough of a priority to get fixed.

https://issues.dlang.org/show_bug.cgi?id=4923

So, unfortunately, it's currently up to the programmer to get it right, and
they won't get an error when they screw it up.

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list