www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20633] New: Struct literals order of evaluation is definition

https://issues.dlang.org/show_bug.cgi?id=20633

          Issue ID: 20633
           Summary: Struct literals order of evaluation is definition
                    dependent, not call dependent
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

```
struct Test
{
    uint a;
    uint b;
    uint c;
}

void main()
{
    auto s = get();
    Test local = { c: 1, a: 2, b: 3 };
    assert(s == local);
}

Test get ()
{
    uint x;
    Test lit = {
        c: ++x,
        a: ++x,
        b: ++x,
    };
    return lit;
}
```

With `dmd -checkaction=context -run bar.d`:

```
core.exception.AssertError bar.d(12): Test(1, 2, 3) !is Test(2, 3, 1)
----------------
??:? _d_assert_msg [0x1027b354a]
??:? _Dmain [0x1027a5e5d]
```

I don't see it being referenced anywhere and it sort-of defeats the purpose of
different ordering.

--
Mar 03 2020