[Issue 16104] Unions should allow fields with destructors, postblits, and invariants

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon May 30 21:08:01 PDT 2016


--- Comment #4 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Walter Bright from comment #2)
> Consider:
>   struct S { ~this(); }
>   struct T { S s; }
> The compiler will automatically create a destructor for T that will call the
> destructor for s, or will add code to do that to the destructor for T.
>   union U { S1 a; S2 b; }
>   U u;
> What happens to RIAA with this?

You mean RAII? There's none of it in unions. As I said, putting data in unions
automatically disables all automatic calls. Putting stuff in unions is purely
layout definition and manipulation. All calls must be inserted by the code
using the union (which is usually encapsulated in a struct wrapping the union
and providing discrimination).


More information about the Digitalmars-d-bugs mailing list