D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 13421 - disallow __gshared members without static
Summary: disallow __gshared members without static
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P4 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-04 09:50 UTC by Marc Schütz
Modified: 2024-12-13 18:25 UTC (History)
2 users (show)

See Also:


Attachments
warns on "static __gshared" variables (1.94 KB, patch)
2014-09-04 13:27 UTC, Ketmar Dark
Details | Diff
druntime code cleanup (1.25 KB, patch)
2014-09-04 13:28 UTC, Ketmar Dark
Details | Diff
phobos code cleanup (678 bytes, patch)
2014-09-04 13:28 UTC, Ketmar Dark
Details | Diff

Note You need to log in before you can comment on or make changes to this issue.
Description Marc Schütz 2014-09-04 09:50:42 UTC
It's surprising that __gshared members are implicitly static. Example:

http://forum.dlang.org/thread/dkqsqyatiwbwyrojpfxb@forum.dlang.org

__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 Ketmar Dark 2014-09-04 11:32:18 UTC
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 Ketmar Dark 2014-09-04 13:27:33 UTC
Created attachment 1413 [details]
warns on "static __gshared" variables

something like this, heh
Comment 3 Ketmar Dark 2014-09-04 13:28:19 UTC
Created attachment 1414 [details]
druntime code cleanup
Comment 4 Ketmar Dark 2014-09-04 13:28:42 UTC
Created attachment 1415 [details]
phobos code cleanup
Comment 5 Marc Schütz 2014-09-04 18:37:02 UTC
`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 Ketmar Dark 2014-09-04 19:43:04 UTC
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 dlangBugzillaToGithub 2024-12-13 18:25:36 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18877

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB