[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
Tue Mar 10 08:49:22 PDT 2015


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

Kenji Hara <k.hara.pg at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to Ketmar Dark from comment #4)
> DMD hackfix is around three lines too (i did that in my branch), but it's a
> dirty hack that shouldn't be in the codebase at all. ;-)
> 
> actually, there are some other places in DMD where such code is used, but it
> seems that this is the only place where bug can be triggered, as the other
> cases triggers errors anyway (such as `if (makeFoo)`, for example).
> 
> but i'm still not sure if moving `addDtorHook()` to `resolveProperties()` is
> the right thing to do. probably not, as `resolveProperties()` seems to be
> used for CTFE too, and CTFE doesn't do `addDtorHook()` call.
> 
> i dreaming of good guide to compiler internals...

resolvePropeties() converts a sort of function expression (VarExp with
FuncDeclaration, DotVarExp with FuncDeclaration, OverExp, etc) to a CallExp if
possible.
addDtorHook() copies the given expression to a temporary to call destructor, if
the expression type is struct.

Those functions are used only in the semantic analysis stage. After the
semantic analysis finished, CTFE engine will interpret the generated AST.

In this case, addDtorHook() should take the result of resolveProperties(). The
wrong call order has been there before the my first contribution for dmd
codebase.

https://github.com/D-Programming-Language/dmd/pull/4474

--


More information about the Digitalmars-d-bugs mailing list