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

          Issue ID: 18575
           Summary: making delegate from member function can lead to
                    unsafe code
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nob...@puremagic.com
          Reporter: bugzi...@digitalmars.com

As reported by Tomer Filiba:

    @safe:

    struct S {
    @safe:
        int x;

        auto foo() {return &bar;}
        void bar() {x = 999;}
    }

    auto f() {
        auto s = S(100);
        return s.foo();
    }

    void main() {
        auto dg = f();
        dg();     // i now have a delegate that will write 999 to some random
stack location
    }

--

Reply via email to