Skip to content

Commit

Permalink
fix Issue 14996 - only(EnumMembers!T) eats all my memory when T : string
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Sep 7, 2015
1 parent 1445df5 commit 2070e8e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/todt.c
Expand Up @@ -792,19 +792,22 @@ dt_t **toDtElem(TypeSArray *tsa, dt_t **pdt, Expression *e)
Type *tbn = tnext->toBasetype();
while (tbn->ty == Tsarray && (!e || tbn != e->type->nextOf()))
{
TypeSArray *tsa = (TypeSArray *)tbn;
len *= tsa->dim->toInteger();
len *= ((TypeSArray *)tbn)->dim->toInteger();
tnext = tbn->nextOf();
tbn = tnext->toBasetype();
}
if (!e) // if not already supplied
e = tsa->defaultInit(Loc()); // use default initializer
Expression_toDt(e, pdt);
dt_optimize(*pdt);
if (e->op == TOKstring)
len /= ((StringExp *)e)->len;
if (e->op == TOKarrayliteral)
len /= ((ArrayLiteralExp *)e)->elements->dim;
if (!e->type->implicitConvTo(tnext)) // Bugzilla 14996
{
// Bugzilla 1914, 3198
if (e->op == TOKstring)
len /= ((StringExp *)e)->len;
else if (e->op == TOKarrayliteral)
len /= ((ArrayLiteralExp *)e)->elements->dim;
}
pdt = dtrepeat(pdt, *pdt, len - 1);
}
return pdt;
Expand Down
50 changes: 32 additions & 18 deletions test/runnable/structlit.d
Expand Up @@ -648,14 +648,14 @@ struct Bug1914a
{
const char[10] i = [1,0,0,0,0,0,0,0,0,0];
char[10] x = i;
int y=5;
int y = 5;
}

struct Bug1914b
{
const char[10] i = [0,0,0,0,0,0,0,0,0,0];
char[10] x = i;
int y=5;
int y = 5;
}

struct Bug1914c
Expand All @@ -668,36 +668,50 @@ struct Bug1914c
int y = 5;
char[2][3] z = j;
char[2][3] w = k;
int v=27;
int v = 27;
char[2][3] u = l;
int t = 718;
}

struct T3198 {
int g = 1;
struct T3198
{
int g = 1;
}

class Foo3198 {
int[5] x = 6;
T3198[5] y = T3198(4);
class Foo3198
{
int[5] x = 6;
T3198[5] y = T3198(4);
}

void test3198and1914()
{
Bug1914a a;
assert(a.y==5, "bug 1914, non-zero init");
assert(a.y == 5, "bug 1914, non-zero init");
Bug1914b b;
assert(b.y==5, "bug 1914, zero init");
assert(b.y == 5, "bug 1914, zero init");
Bug1914c c;
assert(c.y==5, "bug 1914, multilevel init");
assert(c.v==27, "bug 1914, multilevel init2");
assert(c.x[2][1]=='b');
assert(c.t==718, "bug 1914, multi3");
assert(c.u[1][0]=='p');
assert(c.u[1][1]==char.init);
assert(c.y == 5, "bug 1914, multilevel init");
assert(c.v == 27, "bug 1914, multilevel init2");
assert(c.x[2][1] == 'b');
assert(c.t == 718, "bug 1914, multi3");
assert(c.u[1][0] == 'p');
assert(c.u[1][1] == char.init);
auto f = new Foo3198();
assert(f.x[0]==6);
assert(f.y[0].g==4, "bug 3198");
assert(f.x[0] == 6);
assert(f.y[0].g == 4, "bug 3198");
}

/********************************************/
// 14996

enum E14996a : string { confirm = "confirm" }
enum E14996b : long[] { confirm = [1,2,3,4] }

struct S14996
{
E14996a[1] data1;
E14996b[1] data2;
}

/********************************************/
Expand Down

0 comments on commit 2070e8e

Please sign in to comment.