[Issue 17934] New: [scope] scopeness entrypoint for unique/ref-counted missing

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 24 22:42:26 UTC 2017


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 at digitalmars.com
          Reporter: code at 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.

--


More information about the Digitalmars-d-bugs mailing list