Bug 8738 – Struct literal breaks assigment ordering

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-29T22:35:00Z
Last change time
2014-05-21T04:08:07Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
adamsibson

Comments

Comment #0 by adamsibson — 2012-09-29T22:35:13Z
DMD 2.0.6 This behaviour seems inconsistent and unintuitive: void main() { int[3] a = [1,2,3]; // The array is fine a = [4, a[0], 6]; struct S { // The stuct is the problem int a, b, c; } S s = S(1,2,3); s = S(4, s.a, 6); assert(a == [4,1,6]); // What I'd expect assert(s == S(4,4,6)); // Unhelpful } Setting the struct writes s.a before evaluating it while the reverse is true of the array assignment. GDC does what I'd expect and gives both as 4,1,6. This seems to be a bug to me, it creates an easy to miss bug and behaves differently to another common data structure and to the same data structure with a different compiler. Creating a custom constructor for the struct fixes the issue: struct S { int a, b, c; this(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } } assert(s == S(4,1,6));
Comment #1 by clugdbug — 2013-09-23T22:33:00Z
This works in CTFE. I think it's a bug in DMD's glue layer.
Comment #2 by k.hara.pg — 2014-05-17T16:30:01Z
Comment #3 by github-bugzilla — 2014-05-21T04:08:07Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/ab6c35f05543edcdd2ab3d954acfc4685e895b81 fix Issue 8738 - Struct literal breaks assigment ordering https://github.com/D-Programming-Language/dmd/commit/3dff77005b98219ae0f80e2b3e0e5cfc34b368ac Merge pull request #3557 from 9rnsr/fix8738 Issue 8738 - Struct literal breaks assigment ordering