D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 19843 - Derived class has `__dtor` member if base class implements `~this()`
Summary: Derived class has `__dtor` member if base class implements `~this()`
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-03 10:39 UTC by Mike Franklin
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Mike Franklin 2019-05-03 10:39:39 UTC
class B
{
    ~this() {}
}

class C : B
{
    // NOTICE: No destructor   
}

void main()
{
    static assert(__traits(hasMember, B, "__dtor"));
    static assert(!__traits(hasMember, C, "__dtor"), "C should not have a `__dtor` member"); 
    
    static assert(__traits(hasMember, B, "__xdtor"));
    static assert(__traits(hasMember, C, "__xdtor"));
}

Since `C` does not have an implementation for `~this()` it should not have a `__dtor` member.  Both `B` and `C` should have an `__xdtor` member, though.

(At least that is my understanding)
Comment 1 basile-z 2019-05-03 11:02:38 UTC
I think that this report is invalid. For classes you use the derivedMembers traits to see if a particular generation introduce new members. hasMember will work in combination with allMembers which doesn't make the difference.
Comment 2 Mike Franklin 2019-05-03 11:35:03 UTC
Thanks Basile-z.  I think you're right.  I'll close this.
Comment 3 Simen Kjaeraas 2019-05-03 13:04:03 UTC
Basile-z's comment is correct. Proof:

class A {
    ~this() {}
}
class B : A {
}
class C : A {
    ~this() {}
}

// A and B's __dtor are the same:
static assert( __traits(isSame,
    __traits(getMember, A, "__dtor"),
    __traits(getMember, B, "__dtor")));

// A and C's are not:
static assert(!__traits(isSame,
    __traits(getMember, A, "__dtor"),
    __traits(getMember, C, "__dtor")));