Unions destructors and GC precision

Simen Kjaeraas simen.kjaras at gmail.com
Tue Aug 14 22:02:25 PDT 2012


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?

-- 
Simen


More information about the Digitalmars-d mailing list