www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 22366] New: [dip1000] scope variable can be assigned to


          Issue ID: 22366
           Summary: [dip1000] scope variable can be assigned to
                    associative array
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: dkorpel live.nl

Putting a scope variable in an associative array literal gives "scope variable
`x` may not be copied into allocated memory". However, you can still assign it:
int* fun(scope int* x) 
    int*[int] aa;
    aa[0] = x; // should give an error
    return aa[0];

void main() 
    int x;
    assert(fun(&x) != &x); // fails, demonstrating &x was escaped

Oct 08 2021