[Issue 5667] [GSoC] "clear" does not call destructors on structs embedded in structs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jul 27 13:02:38 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5667



--- Comment #8 from Kenji Hara <k.hara.pg at gmail.com> 2011-07-27 13:02:34 PDT ---
(In reply to comment #7)
> Yes, clearly that is a good path.
> 
> But my question is, why __dtor not the same as destroy?  Is there any reason to
> call ~this() without calling all the sub-dtors?

Basically the name "__dtor" is beginning with double underscores, so it is
internal name. At least calling it is not "Right D Way", I think.

(This point is different from C++ syntax: T t(); t.~T();)

> In my opinion, ~this() should implicitly contain the __dtors for all the
> members at the end.

https://github.com/D-Programming-Language/dmd/blob/master/src/clone.c#L496

Looking at dmd source, the internal function name for its purpose may be
"__fieldDtor" or "__aggrDtor", but we can't call them explicitly.

> But yes, having clear use typeid().destroy will fix the original symptom.  If
> we don't intend to fix the root cause, we should at least document that nobody
> should ever use __dtor...

Agreed. Today calling __dtor is obviously incorrect idiom.

----
extern(C) int printf(const(char*) fmt, ...);
struct X
{
  ~this(){ printf("X.~this()\n"); }
}
struct S
{
  X x;
  ~this(){ printf("S.~this()\n"); }
}
void main()
{
  S s;
  s.__dtor();
  printf("-\n");
}
----

Output:
----
S.~this()    // s.__dtor() only call S.~this(), never call s.x.~this()
-
S.~this()
X.~this()
----

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list