[Issue 20171] [REG 2.086.0] null this in invariant after destructor called

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Aug 27 07:26:17 UTC 2019


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

Simen Kjaeraas <simen.kjaras at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |contracts
                 CC|                            |simen.kjaras at gmail.com
            Summary|[REG 2.086.0]  Calling      |[REG 2.086.0] null this in
                   |public function from the    |invariant after destructor
                   |destructor segfaults        |called

--- Comment #1 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
Reduced example:

struct S(T) {
    invariant (&this != null);

    ~this() {
        fun();
    }

    void fun() {
        int i;
    }

    void opEquals(T)(T t) if (false) { }
}

unittest {
    S!int a;
}

As the changed summary indicates, `this` is null in the invariant. It is not
null in ~this() or in fun().

opEquals() is of course never instantiated, but it needs to be there - it needs
to have a template constraint, and it needs to take at least one argument,
which needs to have a name, and needs to be of the type in the template
parameter list.

The invariant is called after fun(), so fun() needs to be there. It can't be
empty, but it obviously doesn't need to do anything sensible.

--


More information about the Digitalmars-d-bugs mailing list