[Issue 11044] Escaping references to lazy argument are allowed and compile to wrong code

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 21 09:02:07 UTC 2018


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

Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
            Summary|Escaping references to lazy |Escaping references to lazy
                   |argument are allowed        |argument are allowed and
                   |                            |compile to wrong code
           Severity|normal                      |critical

--- Comment #3 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
Another test case:

///////////// test.d ////////////
@safe:

auto toDg(E)(lazy E value)
{
    return { return value; };
}

C t;

class C
{
    auto getDg()
    {
        // return () => prop;
        return toDg(prop);
    }

    final @property string prop()
    {
        assert(this is t);
        return null;
    }
}

void smashStack() {
    int[1024] dummy = 0xcafebabe;
}


void main()
{
    t = new C();
    auto result = t.getDg();
    smashStack();
    result();
}
/////////////////////////////////

The compiler needs to either reject the code (accepts-invalid), or generate a
closure (wrong-code).

Upgrading severity as this can manifest as a latent bug (depending on whether
the stack was overwritten or not) in @safe code.

--


More information about the Digitalmars-d-bugs mailing list