Bug 13947 – Padding in empty structs is compared

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-01-07T13:13:00Z
Last change time
2015-02-18T03:42:03Z
Keywords
pull, wrong-code
Assigned to
yebblies
Creator
yebblies

Comments

Comment #0 by yebblies — 2015-01-07T13:13:23Z
This assert fails, because despite being empty, code is emitted to memcmp the structs. While this example is clearly asking for it, this can happen naturally when passing such structs around, as the padding does not have to be preserved. The simple solution is to make empty structs always compare as equal. import core.stdc.string; struct S { } void main() { static assert(S.sizeof == 1); S a; S b; memset(&a, 1, S.sizeof); memset(&b, 2, S.sizeof); assert(a == b); }
Comment #1 by yebblies — 2015-01-07T13:31:11Z
Comment #2 by github-bugzilla — 2015-01-07T22:27:53Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/bb9843932c4b2fbb03e3731e4a4e0d5bfd68d171 Fix Issue 13947 - Padding in empty structs is compared https://github.com/D-Programming-Language/dmd/commit/81673a6173e4254642d76e1d7eaaeec4f6ed0f6b Merge pull request #4262 from yebblies/issue13947 Issue 13947 - Padding in empty structs is compared
Comment #3 by github-bugzilla — 2015-02-18T03:42:03Z