Thread overview
[Issue 17867] @trusted destructor not callable from @safe function
Feb 07, 2018
Simen Kjaeraas
Apr 23, 2018
Simen Kjaeraas
October 02, 2017
https://issues.dlang.org/show_bug.cgi?id=17867

Steven Schveighoffer <schveiguy@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy@yahoo.com

--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> ---
It should work, IMO.

Note that the way this looks internally is kind of bizarre. The actual ~this() function is separate from the one that calls the member's dtor. So I can see how it would not glue together right under the hood.

In other words, the compiler generates a function that does this:

realdtor()
{
   ~this();
   member.~this();
}

And I don't know if there's a way to annotate that one.

--
February 07, 2018
https://issues.dlang.org/show_bug.cgi?id=17867

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |simen.kjaras@gmail.com
         Resolution|---                         |DUPLICATE

--- Comment #2 from Simen Kjaeraas <simen.kjaras@gmail.com> ---


*** This issue has been marked as a duplicate of issue 15246 ***

--
April 22, 2018
https://issues.dlang.org/show_bug.cgi?id=17867

alexanderheistermann@gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |alexanderheistermann@gmail.
                   |                            |com
         Resolution|DUPLICATE                   |---

--- Comment #3 from alexanderheistermann@gmail.com ---
No, this is NOT a duplicate, as the example he had given involved structs not classes. The is no destructor inheritance when it comes to structs.

--
April 23, 2018
https://issues.dlang.org/show_bug.cgi?id=17867

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #4 from Simen Kjaeraas <simen.kjaras@gmail.com> ---
The cause is the same - no inheritance is necessary. Allow me to demonstrate:

struct S1 {
    int value;
    ~this() {
        value = 17;
    }
}

struct S2 {
    S1 a;
    ~this() { }
}

unittest {
    S2 s;
    s.__dtor();

    // Would have been 17 if S1's destructor was run.
    assert(s.a.value == 0);

    // Note the existence of "__xdtor", which is a separate
    // method that calls member destructors.
    pragma(msg, __traits(allMembers, S2));

    s.__xdtor();
    assert(s.a.value == 17);
}



This clearly shows that S2's destructor does *not* call S1's destructor, and thus that the code is valid. (it's validity may be undesired, but it's still valid)

The only value of having this issue open in addition to issue 15246 would be if 15246 is inadequately described. If that's the case, 15246 should be amended, not this issue.

*** This issue has been marked as a duplicate of issue 15246 ***

--