The code is a simplified version of code that used to work in dmd 2.055. I just tried it with 2.058 and received
----------
dmd: interpret.c:100: void CtfeStack::setValue(VarDeclaration*, Expression*): Assertion `v->ctfeAdrOnStack >= 0 && v->ctfeAdrOnStack < stackPointer()' failed.
----------
import std.conv;
// Create a string that unrolls the given expression N times replacing the
// idx char ('i' by default) with the loop number in the expression each time
string unroll(size_t N, size_t i = 0)(string expr, char idx='i') {
static if (i < N) {
string subs_expr;
foreach (c; expr) {
if (c==idx) {
subs_expr ~= to!string(i);
} else {
subs_expr ~= c;
}
}
return subs_expr ~ "\n" ~ unroll!(N,i+1)(expr,idx);
}
return "";
}
struct VectorT(T, int N)
{
T[N] values_;
// triggers CTFE error
bool opEquals(const ref VectorT!(T, N) _rhs) const {
const string expr = "if(values_[z]!=_rhs.values_[z]) return 0;";
mixin( unroll!(N)(expr,'z') );
return 1;
}
}
void main(string[] args)
{
alias VectorT!(double,3) Vec3; // triggers CTFE error
}
Comment #1 by github-bugzilla — 2012-02-20T12:57:59Z