D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7765 - Cannot access __gshared function pointers from static methods
Summary: Cannot access __gshared function pointers from static methods
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-03-24 18:32 UTC by Andrej Mitrovic
Modified: 2012-04-06 09:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Andrej Mitrovic 2012-03-24 18:32:23 UTC
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 Walter Bright 2012-03-24 21:44:57 UTC
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 Andrej Mitrovic 2012-04-06 09:41:02 UTC
(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