← Back to index
|
Original Bugzilla link
Bug 19274 – Inconsistent assignment behavior between struct values and fixed-size arrays
Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-09-28T18:41:29Z
Last change time
2024-12-13T19:00:44Z
Assigned to
No Owner
Creator
Stanislav Blinov
Moved to GitHub: dmd#19490 →
Comments
Comment #0
by stanislav.blinov — 2018-09-28T18:41:29Z
--- static struct S // static for clarity { bool assigned; void opAssign(S) { assigned = true; } void opAssign(ref S) { assigned = true; } } S value; assert(!value.assigned); value = S.init; // i.e. value = move(otherValue), calls opAssign(S) assert(value.assigned); // passes value.assigned = false; value = value; // calls opAssign(ref S) assert(value.assigned); // passes S[1] array; assert(!array.assigned); array = array.init; assert(array[0].assigned); // fails array[0].assigned = false; array = array; assert(array[0].assigned); // fails --- Snippet above illustrates different behavior for a value and an array. It's a weird inconsistency, fixed-size array should behave like an aggregate, but it doesn't. Justification: --- static struct Aggregate // static for clarity { S a; } Aggregate aggr; // same as S[1] aggr; aggr = aggr.init; assert(aggr.a.assigned); // passes --- Same memory, same layout, same aggregated types, different behavior.
Comment #1
by stanislav.blinov — 2018-10-25T22:55:28Z
Some more reference:
https://forum.dlang.org/post/
[email protected]
Comment #2
by robert.schadek — 2024-12-13T19:00:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB
https://github.com/dlang/dmd/issues/19490
DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB