digitalmars.D.bugs - [Issue 16216] New: struct equality compares padding
- via Digitalmars-d-bugs (43/43) Jun 28 2016 https://issues.dlang.org/show_bug.cgi?id=16216
https://issues.dlang.org/show_bug.cgi?id=16216 Issue ID: 16216 Summary: struct equality compares padding Product: D Version: D2 Hardware: x86_64 OS: Linux Status: NEW Keywords: wrong-code Severity: normal Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: ag0aep6g gmail.com ---- struct Result { int value = 0; ubyte len = 0; } void stompStack(ubyte val) { ubyte[1024] x = val; } Result resultWithGarbagePadding() { Result result = void; result.value = 0; result.len = 0; return result; } void main() { Result r; stompStack(1); Result s = resultWithGarbagePadding(); assert(s.tupleof == r.tupleof); /* passes, ok */ assert(*cast(ubyte[5]*)&s == *cast(ubyte[5]*)&r); /* passes, ok */ assert(s == r); /* fails, should pass */ assert(s is r); /* fails, should probably pass */ } ---- Spec says [1]: "Equality for struct objects means the logical product of all equality results of the corresponding object fields." [1] https://dlang.org/spec/expression.html#EqualExpression --
Jun 28 2016