Unions destructors and GC precision
Jonathan M Davis
jmdavisProg at gmx.com
Tue Aug 14 22:09:40 PDT 2012
On Wednesday, August 15, 2012 07:02:25 Simen Kjaeraas wrote:
> On Tue, 14 Aug 2012 22:32:58 +0200, Andrei Alexandrescu
>
> <SeeWebsiteForEmail at erdani.org> wrote:
> > On 8/14/12 3:25 PM, bearophile wrote:
> >> D2 doesn't give you that restriction, and when an union goes out of
> >
> >> scope it calls the destructors of all its fields:
> > That's pretty surprising. "Major bug" doesn't begin to describe it.
> >
> > Unions should call no constructors and no destructors.
>
> That means the default case is unsafe. Should it also be an error
> (or at least a warning) for a union containing types with destructors
> or complex constructors not to have a defined constructor/destructor?
I wouldn't expect unions to be considered @safe in the first place. You're
potentially reintrepreting one type as another with them. And I would expect
that anything in them is in the same boat that anything initialized to void
is. e.g.
Type var = void;
- Jonathan M Davis
More information about the Digitalmars-d
mailing list