www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17763] New: [scope][DIP1000] Error: "cannot take address of

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

          Issue ID: 17763
           Summary: [scope][DIP1000] Error: "cannot take address of scope
                    local" while passing a slice to a scope parameter
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: petar.p.kirov gmail.com

The problem is that the compiler disallows explicitly slicing a static array
and passing the slice to a scope parameter, while if you rely on the implicit
slicing it works without a problem. To reproduce:

$ cat > scope_bug.d << DBUG
 safe:
struct Context { char[] str; }
void use(scope Context[] c) { }
void main()
{
    char[1] s = ' ';
    Context[1] c;
    c[0].str = s;      // <- If this line is commented, it all works.
    c[0] = Context(s); // <- this has the same effect as above.
    use(c);            // OK - this compiles.
    use(c[]);          // NG - doesn't compile, though should be
                       // equivalent to the statement above.
}
DBUG

$ dmd -dip1000 scope_bug.d
scope_bug.d(11): Error: cannot take address of scope local c in  safe function
main

$ dmd --version
DMD64 D Compiler v2.076.0-b1-master-32bb4ed

--
Aug 19 2017