[Issue 11946] "need 'this' to access member" when passing field to template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jan 23 19:51:29 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=11946



--- Comment #14 from Kenji Hara <k.hara.pg at gmail.com> 2014-01-23 19:51:25 PST ---
(In reply to comment #13)
> After some thinking:
> 
> "static" must not affect whether alias parameters receive context pointers.
[snip]
> "static" must only untie the function from its
> immediate surrounding declaration context (struct, class or function frame).

This is just same with the behavior that was implemented by issue 11533. In
git-head, static attribute on template does only unite instantiated functions
and aggregate types from its immediate surrounding declaration context.

void main()
{
    int x;

    // Adding 'static' on local template foo unlinks instantied function
    // from the enclosing main() function context.
    static void foo(alias fun)()
    {
        // x = 10; // NG
        fun();
    }
    static void bar() {}
    foo!bar();
    pragma(msg, is(typeof(&foo!bar) == delegate));  // prints false

    // And nested-ness of the instantiated function only depends on
    // the passed argument on the alias parameter
    void nested() {}
    pragma(msg, is(typeof(&foo!nested) == delegate));  // prints true
}

So in the OP code:

static int f(A...)() { return 0; }
struct S { int x; enum y = f!x(); }

f!x is now tied to the runtime object S, and calling it on context-less scope
is rejected.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list