[Issue 4421] New: Union propagates copy constructors and destructors over all members
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 4 02:59:55 PDT 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 at puremagic.com
ReportedBy: rsinfu at gmail.com
--- Comment #0 from Shin Fujishiro <rsinfu at 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: -------
More information about the Digitalmars-d-bugs
mailing list