[Issue 14107] compiler shouldn't allow to compare unions without custom opEquals

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Mar 22 06:30:39 PDT 2015


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

Marco Leise <Marco.Leise at gmx.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Marco.Leise at gmx.de

--- Comment #1 from Marco Leise <Marco.Leise at gmx.de> ---
Assuming that you were expecting someone to come up with a counter case, in
your case it is an either-or sort of structure and after assigning to sm, bg is
invalid. Disallowing comparisons all-together means that any struct using
unions needs to have its own opEquals that checks which part of the union is
'active' in each instance and compares them if needed.

There are other uses of unions such as:

union Color
{
  uint c;
  struct { ubyte r, g, b, a; }
  ubyte[4] arr;
}

where different representations of the same data are offered and a comparison
of the memory representation is correct.
Having to write a comparison function for every struct that uses a color can
become a chore.

--


More information about the Digitalmars-d-bugs mailing list