It's surprising that __gshared members are implicitly static. Example:
http://forum.dlang.org/thread/[email protected]
__gshared members without an explicit `static` should be deprecated with an appropriate message and later disallowed.
(This would also be an excellent candidate for Brian's dfix.)
Comment #1 by ketmar — 2014-09-04T11:32:18Z
after some thinking i started to believe that we should make exactly the opposite: warn about 'static __gshared' members. '__gshared' implies "one instance", so 'static __gshared' is excessive and meaningless.
Comment #2 by ketmar — 2014-09-04T13:27:33Z
Created attachment 1413
warns on "static __gshared" variables
something like this, heh
Comment #3 by ketmar — 2014-09-04T13:28:19Z
Created attachment 1414
druntime code cleanup
Comment #4 by ketmar — 2014-09-04T13:28:42Z
Created attachment 1415
phobos code cleanup
Comment #5 by schuetzm — 2014-09-04T18:37:02Z
`static __gshared` is currently indeed redundant, but my point is that this isn't obvious. I would expect it to work analogously to a shared member: You can have static and non-static ones of those. As I see it, __gshared merely means "make it shared, but don't complain about unsynchronized access".
Therefore I can't agree that it implies "one instance". It's IMO better to make it explicit.
Comment #6 by ketmar — 2014-09-04T19:43:04Z
specs clearly says:
> __gshared may also be applied to member variables and local variables.
> In these cases, __gshared is equivalent to static, except that the
> variable is shared by all threads rather than being thread local.
http://dlang.org/attribute.html#gshared
so "static __gshared" is a tautology, and i believe that it should be error instead of warning. but error'ing it can break some code, so let's warn for now.
Comment #7 by robert.schadek — 2024-12-13T18:25:36Z