[Issue 23896] New: Contextlessness of local template function not inferred across modules

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat May 6 08:40:18 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=23896

          Issue ID: 23896
           Summary: Contextlessness of local template function not
                    inferred across modules
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: dlang-bugzilla at thecybershadow.net

/////////// a.d ///////////
import b : g;

void f()
{
    /*static*/ void fun()()
    {
    }

    g!fun();
}
/////////// b.d ///////////
auto g(alias fun)()
{
    fun();
}
///////////////////////////

We must specify `static` on `fun` explicitly, otherwise the compilation fails:

b.d(3): Error: function `b.g!(fun).g` cannot access function `fun` in frame of
function `a.f`
a.d(5):        `fun` declared here
a.d(9): Error: template instance `b.g!(fun)` error instantiating

It looks like, in `a.d`, the compiler knows that `fun` is static, so it does
not instantiate `g` with a context pointer. However, when `g` is compiled, it
thinks that it needs a context pointer to call `fun`.

One landmark: before 2.065.0, -o- was successful (but -c still failed).
The change happened in https://github.com/dlang/dmd/pull/2705.

--


More information about the Digitalmars-d-bugs mailing list