D's Destructors are What Scott Meyers Warned Us About

Mike Franklin slavo5150 at yahoo.com
Mon Jul 9 01:19:28 UTC 2018


On Wednesday, 23 May 2018 at 01:59:50 UTC, sarn wrote:
> (I'm referring to Scott's 2014 DConf talk: 
> https://www.youtube.com/watch?v=KAWA1DuvCnQ)
>
> I was actually preparing a DIP about this when Manu posted to 
> the forums about his own related problems with C++ interop.
>
> I traced a bug in some of my D code to my own misunderstanding 
> of how D's destructors actually work.  So I did some research 
> and discovered a bunch of edge cases with using __dtor, __xdtor 
> and hasElaborateDestructor.  I tried reviewing the packages on 
> code.dlang.org and some elsewhere (thankfully only about 1% of 
> D packages use these functions directly) and it turns out I'm 
> not the only one confused.  I don't have time to file bug 
> reports for every package, so, if you're responsible for code 
> that handles destructors manually, please do a review.  There's 
> a *lot* of buggy code out there.
>
> I'm starting this thread to talk about ways to make things 
> better, but first the bad news.  Let's use this idiomatic code 
> as an example of typical bugs:

In the context of your blog post at 
https://theartofmachinery.com/2018/05/27/cpp_classes_in_betterc.html, I'm wondering if the changes in 2.081 help matters at all:  I'm wondering if any of the changes in 2.081 improves the situation here:  e.g. https://dlang.org/changelog/2.081.0.html#cpp_destroy

Mike


More information about the Digitalmars-d mailing list