D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 17073 - [Reg 2.071.0] Priority clash with `void` default initialization of struct fields
Summary: [Reg 2.071.0] Priority clash with `void` default initialization of struct fields
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-08 14:10 UTC by Joseph Rushton Wakeling
Modified: 2017-01-16 23:26 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Joseph Rushton Wakeling 2017-01-08 14:10:13 UTC
If a struct field is default-initialized to `void` then this will override any later default initialization of a whole instance of that struct.

For example, in the following code:

//////////////////////////////
struct Inner
{
    uint alpha = void;
    uint beta = 66;
}

struct Outer
{
    Inner inner = Inner(23, 99);
}


void main ()
{
    import std.stdio : writeln;
    Outer outer;
    outer.inner.writeln;
}
//////////////////////////////

... the result with dmd is that `outer.inner` is `Inner(0, 99)` instead of the expected `Inner(23, 99)`.

Compiling with e.g. LDC produces the expected result of `Inner(23, 99)`.

Note, the issue still appears even if DMD is used with the same frontend version as LDC.  This therefore appears to be a DMD backend issue.
Comment 1 Citrus 2017-01-10 22:23:12 UTC
Covered by DMD's PR https://github.com/dlang/dmd/pull/6427
Comment 2 Martin Nowak 2017-01-13 12:48:19 UTC
This regression was introduced with https://github.com/dlang/dmd/pull/5392 and got released with 2.071.0.
Comment 3 github-bugzilla 2017-01-13 15:04:21 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/5f490432785a36efea2cb4dcda0d3ebb036d6c21
Fix issue 17073 - Do not ignore the explicit initializers

We don't really care about the _init being void-initialized when the
user has supplied an explicit value for a given field of the aggregate.

https://github.com/dlang/dmd/commit/ac7efd9fdff63645e6c9b0278a8307dd07e3bfc1
Merge pull request #6427 from LemonBoy/b17073

Fix issue 17073 - Do not ignore the explicit initializers
merged-on-behalf-of: Martin Nowak <code@dawg.eu>
Comment 4 Joseph Rushton Wakeling 2017-01-13 20:51:18 UTC
Thanks everyone!  Much appreciated :-)
Comment 5 github-bugzilla 2017-01-15 01:21:05 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/5f490432785a36efea2cb4dcda0d3ebb036d6c21
Fix issue 17073 - Do not ignore the explicit initializers

https://github.com/dlang/dmd/commit/ac7efd9fdff63645e6c9b0278a8307dd07e3bfc1
Merge pull request #6427 from LemonBoy/b17073
Comment 6 github-bugzilla 2017-01-16 23:26:30 UTC
Commits pushed to newCTFE at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/5f490432785a36efea2cb4dcda0d3ebb036d6c21
Fix issue 17073 - Do not ignore the explicit initializers

https://github.com/dlang/dmd/commit/ac7efd9fdff63645e6c9b0278a8307dd07e3bfc1
Merge pull request #6427 from LemonBoy/b17073