www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17934] New: [scope] scopeness entrypoint for

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

          Issue ID: 17934
           Summary: [scope] scopeness entrypoint for unique/ref-counted
                    missing
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P3
         Component: dmd
          Assignee: bugzilla digitalmars.com
          Reporter: code dawg.eu

cat > bug.d << CODE
import core.stdc.stdlib;

struct List
{
    Elem front()  safe return scope
    {
        return Elem(data);
    }

    ~this()  trusted scope
    {
        free(data);
        data = null;
    }

     disable this(this);

private:
    void* data;
}

struct Elem
{
private:
    void* data;
}

/**
  There seems to be now way to write this functions so
  that the compiler infers the return value as scope.
 */
List list()  trusted
{
    return List(malloc(1));
}

void test()  safe
{
    Elem elem;
    {
        //scope l = list(); // works with explicit scope
        auto l = list(); // not inferred as scope
        elem = l.front; // escapes, b/c l isn't scoped
    }
}
CODE
dmd -c -dip1000 bug.d
----

Repeatedly ending up with this problem. It doesn't seem possible to contain
allocated data, as there is now way to enforce that the call-site uses a scope
variable.

--
Oct 24 2017