www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4421] New: Union propagates copy constructors and destructors over all members

reply d-bugmail puremagic.com writes:
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



---
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: -------
Jul 04 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4421




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: -------
Jan 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



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: -------
Jan 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



---
*** 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
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



---
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: -------
May 18 2013
prev sibling parent d-bugmail puremagic.com writes:
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



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: -------
Sep 30 2013