[Issue 13116] Should not be able to return ref to 'this'

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jul 12 21:54:37 PDT 2014


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

--- Comment #1 from hsteoh at quickfur.ath.cx ---
Better yet, the following variation shows @safe breakage:
----
import std.stdio;
class C {
        int x;
        this(int _x) { x = _x; }
        ref C evil() @safe {
                return this; // <-- should not compile but does
        }
}
void hmm(int x, int y, ref C c) {
        () @safe {
                c = null;       // corrupt memory -- in @safe block
        }();
        writefln("%d %d", x, y); // prints "0 2"
}
void main() {
        auto c = new C(1);
        auto d = new C(2);
        hmm(1, 2, c.evil()); // N.B., we passed 1 and 2 to hmm()
}
----

--


More information about the Digitalmars-d-bugs mailing list