Skip to content

Commit

Permalink
fix Issue 14398 - Segfault when nested struct in static array accesse…
Browse files Browse the repository at this point in the history
…s context
  • Loading branch information
9rnsr committed Apr 3, 2015
1 parent f234c39 commit e99eb3f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/mtype.c
Expand Up @@ -7682,6 +7682,7 @@ Expression *TypeStruct::defaultInit(Loc loc)
Declaration *d = new SymbolDeclaration(sym->loc, sym);
assert(d);
d->type = this;
d->storage_class |= STCrvalue; // Bugzilla 14398
return new VarExp(sym->loc, d);
}

Expand Down
36 changes: 36 additions & 0 deletions test/runnable/nested.d
Expand Up @@ -2420,6 +2420,41 @@ void test13861()
Foo13861!(n => n) a;
}

/*******************************************/
// 14398

void test14398()
{
int outer;

struct Inner
{
this(this)
{
outer += 42;
}
}

struct Outer
{
Inner inner;

this(int dummy)
{
inner = Inner();

// hidden fields correctly set
assert(this.tupleof[$-1] !is null);
assert(inner.tupleof[$-1] !is null);
}
}

Outer[1] arr1 = [Outer(0)];
assert(outer == 0); // no postblit called on arr1 construction
auto arr2 = arr1;
assert(outer == 42); // inner is copied successfully
}

/*******************************************/

int main()
Expand Down Expand Up @@ -2510,6 +2545,7 @@ int main()
test11297();
test12234();
test13861();
test14398();

printf("Success\n");
return 0;
Expand Down

0 comments on commit e99eb3f

Please sign in to comment.