Bug 19843 – Derived class has `__dtor` member if base class implements `~this()`
Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-05-03T10:39:39Z
Last change time
2020-03-21T03:56:39Z
Assigned to
No Owner
Creator
Mike Franklin
Comments
Comment #0 by slavo5150 — 2019-05-03T10:39:39Z
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 by b2.temp — 2019-05-03T11:02:38Z
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 by slavo5150 — 2019-05-03T11:35:03Z
Thanks Basile-z. I think you're right. I'll close this.
Comment #3 by simen.kjaras — 2019-05-03T13:04:03Z
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")));