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

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Feb 1 17:19:33 PST 2015


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

          Issue ID: 14107
           Summary: compiler shouldn't allow to compare unions without
                    custom opEquals
           Product: D
           Version: unspecified
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: DMD
          Assignee: nobody at puremagic.com
          Reporter: code at dawg.eu

I almost spend 2 days to track down a bug in Higgs that could have been easily
catched by the compiler (see bug 13952).

It just shouldn't be possible to compare unions. Right now this compares the
memory representation, but this is almost always a bug, because a union might
only be partially initialized or the assigned fields might differ.

cat > bug.d << CODE
union Foo
{
    ubyte sm;
    uint bg;
}

void main()
{
    Foo a, b;
    a.bg = 12121212;
    b.bg = 13131313;
    a.sm = 2;
    b.sm = 2;
    assert(a == b); // shouldn't be allowed
}
CODE
dmd -run bug

--


More information about the Digitalmars-d-bugs mailing list