Bug 20475 – Struct of static array of strings is bitwise-compared instead of member-wise
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2019-12-31T17:30:55Z
Last change time
2020-01-01T14:20:40Z
Keywords
pull
Assigned to
No Owner
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2019-12-31T17:30:55Z
Code:
------
struct S {
string[2] x;
}
void main() {
auto s = S(["a", "b"]);
auto t = S(["a", ""]);
t.x[1] ~= "b";
assert(s == t);
}
------
Expected result: assertion should pass.
Actual result: assertion fails.
Looking at the disassembly, it appears that the struct comparison with == is implemented as a bitwise comparison, which is wrong because 'string' is not a POD and therefore the static array member ought to be compared member-wise rather that bitwise.
Comment #1 by dlang-bot — 2020-01-01T10:18:19Z
@rainers created dlang/dmd pull request #10706 "fix Issue 20475 - Struct of static array of strings is bitwise-compar…" fixing this issue:
- fix Issue 20475 - Struct of static array of strings is bitwise-compared instead of member-wise
needOpEquals should check the type of the elements of static arrays, too.
https://github.com/dlang/dmd/pull/10706
Comment #2 by dlang-bot — 2020-01-01T14:20:40Z
dlang/dmd pull request #10706 "fix Issue 20475 - Struct of static array of strings is bitwise-compar…" was merged into stable:
- 9da6367bde50cee019083eca53eba6ab956f1031 by Rainer Schuetze:
fix Issue 20475 - Struct of static array of strings is bitwise-compared instead of member-wise
needOpEquals should check the type of the elements of static arrays, too.
https://github.com/dlang/dmd/pull/10706