Skip to content

Commit

Permalink
Merge pull request #4329 from 9rnsr/fix_ctfe
Browse files Browse the repository at this point in the history
Issue 14022 & 14023 - [CTFE] postblits/destructors not called on static array assignment
  • Loading branch information
WalterBright committed Jan 25, 2015
2 parents 15e52b1 + b4829a9 commit f96ab68
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 269 deletions.
2 changes: 2 additions & 0 deletions src/ctfe.h
Expand Up @@ -103,6 +103,8 @@ class CTFEExp : public Expression
public:
CTFEExp(TOK tok);

char *toChars();

// Handy instances to share
static CTFEExp *cantexp;
static CTFEExp *voidexp;
Expand Down
43 changes: 37 additions & 6 deletions src/ctfeexpr.c
Expand Up @@ -174,6 +174,19 @@ CTFEExp::CTFEExp(TOK tok)
type = Type::tvoid;
}

char *CTFEExp::toChars()
{
switch (op)
{
case TOKcantexp: return (char *)"<cant>";
case TOKvoidexp: return (char *)"<void>";
case TOKbreak: return (char *)"<break>";
case TOKcontinue: return (char *)"<continue>";
case TOKgoto: return (char *)"<goto>";
default: assert(0); return NULL;
}
}

Expression *UnionExp::copy()
{
Expression *e = exp();
Expand Down Expand Up @@ -347,12 +360,30 @@ UnionExp copyLiteral(Expression *e)
}
if (e->op == TOKslice)
{
// Array slices only do a shallow copy
new(&ue) SliceExp(e->loc, ((SliceExp *)e)->e1,
((SliceExp *)e)->lwr, ((SliceExp *)e)->upr);
Expression *r = ue.exp();
r->type = e->type;
return ue;
SliceExp *se = (SliceExp *)e;
if (se->type->toBasetype()->ty == Tsarray)
{
// same with resolveSlice()
if (se->e1->op == TOKnull)
{
new(&ue) NullExp(se->loc, se->type);
return ue;
}
ue = Slice(se->type, se->e1, se->lwr, se->upr).copy();
assert(ue.exp()->op == TOKarrayliteral);
ArrayLiteralExp *r = (ArrayLiteralExp *)ue.exp();
r->elements = copyLiteralArray(r->elements);
r->ownedByCtfe = true;
return ue;
}
else
{
// Array slices only do a shallow copy
new(&ue) SliceExp(e->loc, se->e1, se->lwr, se->upr);
Expression *r = ue.exp();
r->type = e->type;
return ue;
}
}
if (e->op == TOKclassreference)
{
Expand Down

0 comments on commit f96ab68

Please sign in to comment.