Destructor called while object is still alive

Ola Fosheim Grøstad ola.fosheim.grostad at gmail.com
Fri Oct 23 06:57:05 UTC 2020


On Friday, 23 October 2020 at 06:37:43 UTC, Daniel Kozak wrote:
> On Fri, Oct 23, 2020 at 8:20 AM frame via Digitalmars-d < 
> digitalmars-d at puremagic.com> wrote:
>
>>  Even this is a "intelligent"
>> feature by the compiler for non reachable code like that loop,
>> it's still confusing. There are maybe situations while the 
>> object
>> should stay in background, eg. socket related/event stuff. If
>> there is a valid pointer, there is no excuse to reap it.
>>
>>
> There is no use of foo anywhere so there is no reason to not 
> collect it.

It is in use until the end of main. Think locking. Seems like the 
pointer is optimized away and then the GC collects. Makes RAII 
useless with GC.

Basically a consequence of the optimizer assuming that there is 
no GC. A rather serious correctness issue.




More information about the Digitalmars-d mailing list