[Issue 19141] New: Destructors are called for multiple anonymous union members
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Aug 5 17:44:11 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=19141
Issue ID: 19141
Summary: Destructors are called for multiple anonymous union
members
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
Example code:
---
import std.stdio: writeln;
struct S1
{
~this() { writeln("Destroying S1"); }
}
struct S2
{
~this() { writeln("Destroying S2"); }
}
struct S3
{
union
{
S1 one;
S2 two;
}
~this() { writeln("Destroying S3"); }
}
void main()
{
S3 three;
}
---
Output:
Destroying S3
Destroying S2
Destroying S1
Since `one` and `two` are members of the same union, calling both destructors
will always lead to undefined behavior.
Changing the anonymous union to a named union causes both the S1 and S2
destructor calls to be omitted.
Possibly related to Issue 4421.
--
More information about the Digitalmars-d-bugs
mailing list