D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5338 - __gshared on class member variable implies static?
Summary: __gshared on class member variable implies static?
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-10 01:23 UTC by Brad Roberts
Modified: 2012-01-20 13:40 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Brad Roberts 2010-12-10 01:23:07 UTC
module buggshared;

class A
{
    shared static this()
    {  
        supported["foo"] = "bar";
    }

    __gshared string[string] supported;
}

This builds, which means that__gshared in a class scope implies static?  That doesn't seem like a good idea.  I didn't find where that's documented either.
Comment 1 Trass3r 2011-02-23 02:45:22 UTC
Makes sense to me.
How can a class member be __gshared without being static?
Comment 2 Brad Roberts 2011-02-23 12:47:31 UTC
Static means there's a single instance.  Shared simply means more than one thread has visibility to it.  Two very different properties.  Neither implies the other.
Comment 3 Walter Bright 2012-01-20 13:40:39 UTC
From attributes.html:

"__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."