[Issue 2569] static arrays in CTFE functions don't compile
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jul 22 00:36:19 PDT 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2569
Don <clugdbug at yahoo.com.au> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |patch
--- Comment #2 from Don <clugdbug at yahoo.com.au> 2009-07-22 00:36:19 PDT ---
Turned out to be slightly more involved than I thought, there are a few special
cases. I think I've captured them all.
Extended test case:
-------------------
struct Foo {
int m;
}
int foo()
{
short [4] a = [2, 3, 4, 6];
double [27] b = 2.0;
cfloat[2] c;
auto d = [2, 3, 4, 5];
Foo[2] e = [Foo(3), Foo(2)];
// ushort [3] f = [1, 2]; // Uncomment to generate a compile-time error.
d[2..6] = 4;
a[1] = 7;
return a[0]-3;
}
static assert(foo()==-1);
PATCH: interpret.c, line 1464 in BinExp::interpretAssignCommon(),
before checking for the other cases.
------------
// Assignment/initialization of static arrays
if (e1->op == TOKslice && ((SliceExp *)e1)->e1->op==TOKvar) {
SliceExp * sexp = (SliceExp *)e1;
VarExp *ve = (VarExp *)(sexp->e1);
VarDeclaration *v = ve->var->isVarDeclaration();
Type *t = v->type->toBasetype();
if (t->ty == Tsarray){
size_t dim = ((TypeSArray *)t)->dim->toInteger();
if (e2->op == TOKarrayliteral) {
// Static array assignment from literal
ArrayLiteralExp *ae = (ArrayLiteralExp *)e2;
// Ensure length is the same
if (ae->elements->dim != dim) {
error("Array length mismatch");
return e;
}
v->value = ae;
return ae;
}
if (t->nextOf()->ty == e2->type->ty) {
// Static array block assignment
Expressions *elements = new Expressions();
elements->setDim(dim);
for (size_t i = 0; i < dim; i++)
elements->data[i] = e2;
ArrayLiteralExp *ae = new ArrayLiteralExp(0, elements);
ae->type = v->type;
v->value = ae;
return e2;
}
}
}
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list