Bug 7765 – Cannot access __gshared function pointers from static methods
Status
RESOLVED
Resolution
INVALID
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-24T18:32:00Z
Last change time
2012-04-06T09:41:02Z
Assigned to
nobody
Creator
andrej.mitrovich
Comments
Comment #0 by andrej.mitrovich — 2012-03-24T18:32:23Z
class Foo
{
static int test()
{
return c_func();
}
extern(C) __gshared int c_func();
}
test.d(7): Error: need 'this' to access member c_func
The docs say:
__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.
And true enough it works fine with regular variables:
class Foo
{
static int getX() { return x; }
extern(C) __gshared int x;
}
But not with function pointers, unless they're declared outside the class. I think this is a bug.
Comment #1 by bugzilla — 2012-03-24T21:44:57Z
c_func() is a function, not a function pointer nor a variable, and so __gshared has no effect on it.
Not a bug.
Comment #2 by andrej.mitrovich — 2012-04-06T09:41:02Z
(In reply to comment #1)
> c_func() is a function, not a function pointer nor a variable, and so __gshared
> has no effect on it.
>
> Not a bug.
Ok. But why is 'static' required? This won't work:
class Foo
{
static int test()
{
return c_func();
}
extern(C) int c_func();
}
test.d(5): Error: need 'this' to access member c_func