On Wed, 15 Aug 2012 07:09:40 +0200, Jonathan M Davis <[email protected]>
wrote:
On Wednesday, August 15, 2012 07:02:25 Simen Kjaeraas wrote:
On Tue, 14 Aug 2012 22:32:58 +0200, Andrei Alexandrescu
<[email protected]> 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.
True, when the unioned types are or contain pointers. With POD there
should be no problem.
--
Simen