Comment #2 by petar.p.kirov — 2018-02-05T17:23:25Z
All of these examples should *never* compile. The whole point of `shared` is to statically disallow accidental access shared mutable state. > 90% of all functions in phobos have no business touching `shared`/`__gshared` variables, especially `std.getopt`.
`std.getopt` can be safely used to set:
* function local variables
* (static) thread-local variables
* immutable global variables from shared static constructors (not sure if this currently works, but it should be ok from memory model perspective)
I consider everything else to potentially trigger undefined behavior.
Comment #3 by greensunny12 — 2018-02-05T17:56:47Z
> immutable global variables from shared static constructors (not sure if this currently works, but it should be ok from memory model perspective)
No this doesn't work at the moment.
For future readers: it has been used by people before (https://github.com/vibe-d/vibe.d/pull/2060).
Comment #4 by robert.schadek — 2024-12-13T18:56:43Z