Thread overview
[Issue 14107] compiler shouldn't allow to compare unions without custom opEquals
Mar 22, 2015
Denis Shelomovskij
Mar 22, 2015
Marco Leise
Feb 10, 2016
Marco Leise
Dec 17, 2022
Iain Buclaw
March 22, 2015
https://issues.dlang.org/show_bug.cgi?id=14107

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

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

--
March 22, 2015
https://issues.dlang.org/show_bug.cgi?id=14107

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

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

--- Comment #1 from Marco Leise <Marco.Leise@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.

--
June 09, 2015
https://issues.dlang.org/show_bug.cgi?id=14107

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |D2

--
February 10, 2016
https://issues.dlang.org/show_bug.cgi?id=14107

--- Comment #2 from Marco Leise <Marco.Leise@gmx.de> ---
I think when I wrote the above I wasn't aware that unions can have toString(). Can they also offer a custom opEquals() ? That would be more convenient for cases like the color example or float/int "reinterpret cast" named unions which can perform the comparison themselves instead of the one in Higgs that is anonymously embedded in a struct with a tag.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=14107

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--