[Issue 20809] return statement might access memory from destructed temporary

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 13 14:08:44 UTC 2020


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

welkam <wwwelkam at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wwwelkam at gmail.com

--- Comment #5 from welkam <wwwelkam at gmail.com> ---
Even more reduced test case
----------------------------
struct S
{
    int a;
    ~this()
    {
        a = 0;
    }
}

void main()
{
    assert(foo() == 2); // foo() is 0
}

int foo()
{
    //bug is here
    return S(2).a; // destructor of the struct is called in this scope and sets
a to 0
}

--


More information about the Digitalmars-d-bugs mailing list