Skip to content

Commit

Permalink
Fix issue 17073 - Do not ignore the explicit initializers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LemonBoy authored and MartinNowak committed Jan 13, 2017
1 parent b35ec9c commit 5f49043
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,12 @@ private void membersToDt(AggregateDeclaration ad, DtBuilder dtb,
{
if (elements && !(*elements)[firstFieldIndex + i])
continue;
else if (ad.fields[i]._init && ad.fields[i]._init.isVoidInitializer())
continue;

if (!elements || !(*elements)[firstFieldIndex + i])
{
if (ad.fields[i]._init && ad.fields[i]._init.isVoidInitializer())
continue;
}

VarDeclaration vd;
size_t k;
Expand All @@ -753,8 +757,12 @@ private void membersToDt(AggregateDeclaration ad, DtBuilder dtb,

if (elements && !(*elements)[firstFieldIndex + j])
continue;
if (v2._init && v2._init.isVoidInitializer())
continue;

if (!elements || !(*elements)[firstFieldIndex + j])
{
if (v2._init && v2._init.isVoidInitializer())
continue;
}

// find the nearest field
if (!vd || v2.offset < vd.offset)
Expand Down
13 changes: 13 additions & 0 deletions test/runnable/b17073.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
struct S0
{
int x = void;
}
struct S1
{
S0 x = S0(42);
}
void main()
{
S1 x;
assert(x.x.x == 42);
}

0 comments on commit 5f49043

Please sign in to comment.