[Issue 17246] [REG2.053] Extra destructor call.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jul 2 07:36:29 PDT 2017


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dlang-bugzilla at thecybershad
                   |                            |ow.net
            Summary|Extra destructor call.      |[REG2.053] Extra destructor
                   |                            |call.
           Severity|critical                    |regression

--- Comment #1 from Vladimir Panteleev <dlang-bugzilla at thecybershadow.net> ---
Same example with asserts replacing writelns, and checks based on simple
reference counting:

struct Foo
{
    int* rc;
    this(int val)
    {
        rc = new int;
        (*rc) = 1;
    }
    this(this)
    {
        (*rc)++;
    }
    ~this()
    {
        if (rc)
        {
            assert(*rc > 0);
            (*rc)--;
        }
    }
}

struct Bar
{
    Foo foo;
    this(Foo foo, bool)
    {
        this.foo = foo;
    }
}

bool fun(bool val) { return !val; }

auto genBar(bool flag)
{
    return flag ? Bar() : Bar(Foo(10), fun(!flag));
}

void main(string[] args)
{
    auto bar = genBar(args.length == 0);
}

This appears to be a regression, as it worked before 2.052.

Introduced in
https://github.com/dlang/dmd/commit/e764b3949ae0f95f8fc4d7d2e9114e29fee12493

--


More information about the Digitalmars-d-bugs mailing list