[Issue 14264] Destructor not called when struct is returned from a parenthesis-less function call

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Mar 9 08:25:19 PDT 2015


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

Ketmar Dark <ketmar at ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar at ketmar.no-ip.org

--- Comment #1 from Ketmar Dark <ketmar at ketmar.no-ip.org> ---
this is due to inconsistency in `ExpStatement::semantic()`. the code is:

  exp = exp->semantic(sc);  // (1)
  exp = exp->addDtorHook(sc); // (2)
  exp = resolveProperties(sc, exp); // (3)

for "bracket call" `exp` in (1) CallExp, and `addDtorHook` is correctly adds
temporary to store `Foo` and destroy it later (actually, rewrites call as comma
expression).

but for "bracketless call" `exp` in (1) is `IdentifierExp`, which is changed to
`VarExp` by semantic analyzer. so in (2) we have simply `VarExp`, which,
obviously, not a call and doesn't need any destructors to be added. and later
`resolveProperties` see that our `VarExp` is really a call, and returns
`CallExp`, but alas, it's too late to add dtors.

but i'm still not Kenji ;-), so i don't know if it's ok to just call
`resolveProperties` before adding destructor hook. i bet it is wrong though,
'cause `resolveProperties` is a complex thing and i still have to found what it
really does. there are no helpful comments in DMD source about it. :-(

--


More information about the Digitalmars-d-bugs mailing list