www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20674] New: [DIP1000] inference of `scope` is easily confused

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

          Issue ID: 20674
           Summary: [DIP1000] inference of `scope` is easily confused
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: rejects-valid, safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: ag0aep6g gmail.com

This compiles as expected:

----
int* f()(int* p)
{
    static int g;
    g = 0;
    return new int;
}

int* g()  safe
{
    int x;
    return f(&x);
}
----

This doesn't, but should:

----
int* f()(int* p)
{
    static int g;
    g = 0;
    auto p2 = p; /* the only difference */
    return new int;
}

int* g()  safe
{
    int x;
    return f(&x); /* Error: reference to local variable `x` assigned to
non-scope parameter `p` calling test.f!().f */
}
----

--
Mar 15