digitalmars.D.bugs - [Issue 14107] New: compiler shouldn't allow to compare unions
- via Digitalmars-d-bugs (37/37) Feb 01 2015 https://issues.dlang.org/show_bug.cgi?id=14107
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 puremagic.com Reporter: code 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 --
Feb 01 2015