[Issue 13947] New: Padding in empty structs is compared
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Wed Jan 7 05:13:23 PST 2015
https://issues.dlang.org/show_bug.cgi?id=13947
Issue ID: 13947
Summary: Padding in empty structs is compared
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Keywords: wrong-code
Severity: normal
Priority: P1
Component: DMD
Assignee: yebblies at gmail.com
Reporter: yebblies at gmail.com
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);
}
--
More information about the Digitalmars-d-bugs
mailing list