On Wednesday, 25 January 2017 at 12:36:02 UTC, Stefan Koch wrote:
newCTFE is green now on all platforms!

I just found an interesting bug just now.
The following code would cause newCTFE to segfault.

char* initPtr()
{
    return cast(char*) size_t.max;
}

static assert(cast(size_t)initPtr() == size_t.max);

Because it would try to return the char-value at heap-address size_t.max; newCTFE allocates a 16MB heap by default and therefore the address was hopelessly out-of-bounds.

The reason this was not detected before is because:
  `cast(char*) size_t.max;`
does not actually produce a cast expression.
But rather an IntegerLiteral with the type char*.

After dealing with dmd for 7 months, I could figure out this bug in a day. If I had run into this earlier I would have been stuck for weeks :)

Reply via email to