copy-ctor's

Manu turkeyman at gmail.com
Mon May 27 00:41:22 UTC 2019


On Sun, May 26, 2019 at 4:55 PM Ola Fosheim Grøstad via Digitalmars-d
<digitalmars-d at puremagic.com> wrote:
>
> On Sunday, 26 May 2019 at 23:45:05 UTC, Ola Fosheim Grøstad wrote:
> > On Sunday, 26 May 2019 at 22:33:48 UTC, Manu wrote:
> >> Oh, no.. that's search results, listed recent first. I didn't
> >> realise the forum could do that.
> >
> > Oh yes, that can be confusing.
> >
> > Untagged unions doesn't really play well with destructors in
> > any language. I think C++ requires that those destructors are
> > ignored and that the union's destructor should do the cleanup.
> > Seems like a thing that is easy to forget though…
>
> I vaguely remember Bearophile suggest that the union/struct
> should provide a means to identify which type the union was
> holding.
>
> One usually has a union in a struct that also contains a tag of
> some sort that signifies the type of the union… but I think this
> is outside the scope of D as a language.
>
> So perhaps one should not be allowed to have destructors in
> untagged unions and encourage the use of tagged unions…

Well I'm obviously implementing a tagged union.
The language just needs to make the feature available, and let me wrap it up.
The proper thing to do here, is disable field-copy/destruction for
items in unions, and if the owning type doesn't declare
copy-ctor/destructors, then the default functions should be @disabled
rather than generated from fields as usual.
It should also be un- at safe to reference a member of a union from any
method, and from there we have everything we need to write tooling.



More information about the Digitalmars-d mailing list