www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17892] New: Scope analysis with -dip1000 fails for templated

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

          Issue ID: 17892
           Summary: Scope analysis with -dip1000 fails for templated
                    structs
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: per.nordlow gmail.com

When

struct S {
     safe:
    int[ 128] x;
    scope ref int front() return {
        return x[ 0];
    }
    scope int* pointer() return {
        return &x[ 0];
    }
}
ref int testFront() {
    S s;
    return s.front(); // error
}
int* testPointer() {
    S s;
    return s.pointer(); // error
}

is turned into a template

 safe:
struct ST( T) {
     safe:
    T[ 128] x;
    scope ref T front() return {
        return x[ 0];
    }
    scope T* pointer() return {
        return &x[ 0];
    }
}

scope analysis (with -dip1000) no longer forbids escaping of reference and
pointer as in

ref int testFrontT() {
    ST!int s;
    return s.front(); // reference to stack element escapes
}
int* testPointerT() {
    ST!int s;
    return s.pointer(); // pointer to stack element escapes
}

--
Oct 10 2017