Thread overview
[Issue 4421] New: Union propagates copy constructors and destructors over all members
Jul 04, 2010
Shin Fujishiro
Jan 24, 2012
Walter Bright
May 18, 2013
Maxim Fomin
May 18, 2013
Maxim Fomin
Sep 30, 2013
Denis Shelomovskij
July 04, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4421

           Summary: Union propagates copy constructors and destructors
                    over all members
           Product: D
           Version: 2.041
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: rsinfu@gmail.com


--- Comment #0 from Shin Fujishiro <rsinfu@gmail.com> 2010-07-04 02:59:50 PDT ---
Copy constructor and destructor are invoked on every field of a union.  It must be compile error to define a union containing any object which has a copy-constructor and/or a destructor -- since calling cpctor or dtor on 'non-active members' leads to undefined behavior.

This program compiles:
--------------------
import std.stdio;
void main()
{
    U u, v;
    v = u;
}
union U
{
    R r;
    S s;
}
struct R
{
    this(this) { writeln("R : this(this)"); }
    ~this()    { writeln("R : ~this()"); }
}
struct S
{
    this(this) { writeln("S : this(this)"); }
    ~this()    { writeln("S : ~this()"); }
}
--------------------

And prints this lines:
--------------------
R : this(this)
S : this(this)
S : ~this()
R : ~this()
S : ~this()
R : ~this()
S : ~this()
R : ~this()
--------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4421



--- Comment #1 from github-bugzilla@puremagic.com 2012-01-23 21:24:42 PST ---
Commit pushed to https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/86ecdab02a3cdcc81c9f302b9e35212148cb06ed
fix Issue 4421 - Union propagates copy constructors and destructors over all
members

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 24, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4421


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|spec                        |
                 CC|                            |bugzilla@digitalmars.com
            Version|2.041                       |D2
           Severity|major                       |normal


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2012-01-23 21:25:53 PST ---
Fixed spec to disallow them. It's now a compiler bug that they are accepted.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4421


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-05-18 13:30:15 PDT ---
*** Issue 8576 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 18, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4421


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru
           Severity|normal                      |major


--- Comment #4 from Maxim Fomin <maxim@maxim-fomin.ru> 2013-05-18 13:39:25 PDT ---
In the first order unions and structs both belong to aggregate type category. Normally they should share few common characteristics, but currently in D they are very close to each other so that when you use a union, you use a struct except ctor ability and member storage. Following futures are supported by unions:

* postblits
* dtors
* member functions
* operator overloading
* shared static constructors
* invariants
* and other features...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 30, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=4421


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg@gmail.com


--- Comment #5 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2013-09-30 17:20:43 MSD ---
This is an old and easily fixable major accepts-invalid bug. Probably it's just forgotten. What about to fix it?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------