Thread overview
[Issue 8738] New: Struct assignment constructor order of operations DMD 2.0.6
[Issue 8738] Struct literal breaks assigment ordering
Jan 03, 2013
yebblies
Sep 24, 2013
Don
September 30, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8738

           Summary: Struct assignment constructor order of operations DMD
                    2.0.6
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: adamsibson@hotmail.com


--- Comment #0 from adamsibson@hotmail.com 2012-09-29 22:35:13 PDT ---
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));

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 03, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8738


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |yebblies@gmail.com
            Summary|Struct assignment           |Struct literal breaks
                   |constructor order of        |assigment ordering
                   |operations DMD 2.0.6        |
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 24, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=8738



--- Comment #1 from Don <clugdbug@yahoo.com.au> 2013-09-23 22:33:00 PDT ---
This works in CTFE. I think it's a bug in DMD's glue layer.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------