[Issue 17049] [scope] member methods not escape checked like free functions

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Feb 25 08:52:23 PST 2017


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

Martin Nowak <code at dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[scope] class references    |[scope] member methods not
                   |are not escape checked like |escape checked like free
                   |pointers                    |functions

--- Comment #8 from Martin Nowak <code at dawg.eu> ---
The Handle case would need to look like this, w/ a free function dmd correctly
prevents escaping.

struct Handle
{
    @safe:
    int fd;
    @disable this(this);
    ~this() {}
} // not-copyable

static @safe ref int get1(return ref scope Handle _this)
{
    return _this.fd;
}

int* escape1() @safe
{
    Handle h;
    auto p = &h.get1();
    return p;
}

static @safe int* get2(return ref scope Handle _this)
{
    return &_this.fd;
}

int* escape2() @safe
{
    Handle h;
    auto p = h.get2();
    return p;
}

----
/tmp/tmp.Rm7L5V5FW1/bug.d(17): Error: cannot take address of ref return of
get1() in @safe function escape1 // this restriction migth get removed at some
point
/tmp/tmp.Rm7L5V5FW1/bug.d(18): Error: scope variable p may not be returned
/tmp/tmp.Rm7L5V5FW1/bug.d(30): Error: scope variable p may not be returned
----

So the problematic bug is that member methods are not correctly checked.

--


More information about the Digitalmars-d-bugs mailing list