[Issue 17730] [scope][dip1000] Can escape references to scope classes by moving

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Aug 26 14:18:24 PDT 2017


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

Walter Bright <bugzilla at digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla at digitalmars.com
          Component|dmd                         |phobos
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from Walter Bright <bugzilla at digitalmars.com> ---
Breaking it down to the following code:

import std.algorithm;

T moveImpl(T)(ref T source) {
    T result = void;
    moveEmplace(source, result);
    return result;
}

T trustedMoveImpl(T)(ref T source) @trusted {
    return moveImpl(source);
}

T move(T)(ref T source) {
    // test @safe destructible
    static if (__traits(compiles, (T t) @safe {}))
        return trustedMoveImpl(source); // this is the path taken
    else
        return moveImpl(source);
}

class A { }

A makeA() @safe {
        scope a = new A();
        return move(a);   // should fail
}

The trouble is that moveEmplace() is @system, but trustedMoveImpl() paints it
to be @trusted, thus defeating the scope checks.

Re-categorized as a Phobos issue.

--


More information about the Digitalmars-d-bugs mailing list