[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:05:23 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16104

--- Comment #3 from Andrei Alexandrescu <andrei at erdani.com> ---
(In reply to Walter Bright from comment #1)
> In C++:
> 
>   struct S {  ~S(); };
>   union U  { S s; };
> 
> g++ -c foo.cpp
> foo.cpp:2:14: error: member 'S U::s' with destructor not allowed in union
>  union U  { S s; };
>               ^
> foo.cpp:2:14: note: unrestricted unions only available with -std=c++11 or
> -std=gnu++11
> 
> 
> What was C++11's rationale?

Forgot to mention Lois Goldthwaite's work on this:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2544.pdf. It's a great
fix of C++ without which implementing things like variant types portably was
next to impossible.

--


More information about the Digitalmars-d-bugs mailing list