Skip to content

Commit

Permalink
Merge pull request #774 from donc/ctfe7568
Browse files Browse the repository at this point in the history
7568 pragma(msg) segfaults with an aggregate including a class.
  • Loading branch information
WalterBright committed Mar 1, 2012
2 parents f285170 + 2e2d01d commit 4983d32
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/interpret.c
Expand Up @@ -986,7 +986,7 @@ Expression *ctfeCat(Type *type, Expression *e1, Expression *e2)
return Cat(type, e1, e2);
}

void scrubArray(Loc loc, Expressions *elems);
bool scrubArray(Loc loc, Expressions *elems);

/* All results destined for use outside of CTFE need to have their CTFE-specific
* features removed.
Expand All @@ -1007,7 +1007,8 @@ Expression *scrubReturnValue(Loc loc, Expression *e)
{
StructLiteralExp *se = (StructLiteralExp *)e;
se->ownedByCtfe = false;
scrubArray(loc, se->elements);
if (!scrubArray(loc, se->elements))
return EXP_CANT_INTERPRET;
}
if (e->op == TOKstring)
{
Expand All @@ -1016,29 +1017,35 @@ Expression *scrubReturnValue(Loc loc, Expression *e)
if (e->op == TOKarrayliteral)
{
((ArrayLiteralExp *)e)->ownedByCtfe = false;
scrubArray(loc, ((ArrayLiteralExp *)e)->elements);
if (!scrubArray(loc, ((ArrayLiteralExp *)e)->elements))
return EXP_CANT_INTERPRET;
}
if (e->op == TOKassocarrayliteral)
{
AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)e;
aae->ownedByCtfe = false;
scrubArray(loc, aae->keys);
scrubArray(loc, aae->values);
if (!scrubArray(loc, aae->keys))
return EXP_CANT_INTERPRET;
if (!scrubArray(loc, aae->values))
return EXP_CANT_INTERPRET;
}
return e;
}

// Scrub all members of an array
void scrubArray(Loc loc, Expressions *elems)
// Scrub all members of an array. Return false if error
bool scrubArray(Loc loc, Expressions *elems)
{
for (size_t i = 0; i < elems->dim; i++)
{
Expression *m = elems->tdata()[i];
if (!m)
continue;
m = scrubReturnValue(loc, m);
if (m == EXP_CANT_INTERPRET)
return false;
elems->tdata()[i] = m;
}
return true;
}


Expand Down
12 changes: 12 additions & 0 deletions test/fail_compilation/pragmamsg7568.d
@@ -0,0 +1,12 @@
// REQUIRED_ARGS: -c -o-

class C7568 {}
struct S7568 { C7568 c; }
auto test7568a() { return [new C7568]; }
auto test7568b() { return S7568(new C7568); }

pragma(msg, test7568a());
pragma(msg, test7568b());



0 comments on commit 4983d32

Please sign in to comment.