newCTFE report July
Stefan Koch
uplink.coder at googlemail.com
Wed Jul 18 18:28:30 UTC 2018
Hi Guys, last month I did the work make this snippet compile and
execute correctly:
static immutable four = [1, 2, 3, 4];
int fn(int idx = 2)
{
int fn2(const int* x)
{
return x[idx];
}
return fn2(&four[0]) + *(&four[0]);
}
static assert(fn() == 4);
There where two major problems with this one.
1. There was the circular initialization-detected which would
object to referencing `&four` twice in the same expression.
2. there was the problem of the IndexExp being unaware of being
inside an AddrExp which would cause it to first evaluate four[0]
to 1, and then trying to take the address of literal one (which
is zero as the marker for an invalid address).
Fixing this involved adding a special case to how &x[y] is
handled.
This solution does complicate the internals of newCTFE a bit, and
I hope to simplify it once other blocking problems are out of the
way.
More information about the Digitalmars-d
mailing list