Skip to content

Commit

Permalink
Fix Issue 7175 - Zero-length static array .ptr is always null
Browse files Browse the repository at this point in the history
  • Loading branch information
yebblies committed Nov 27, 2013
1 parent 5f033bf commit 36c9b64
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
5 changes: 1 addition & 4 deletions src/cast.c
Expand Up @@ -1073,10 +1073,7 @@ Expression *Expression::castTo(Scope *sc, Type *t)
{
//printf("Converting [dim] to *\n");

if (typeb->size(loc) == 0)
e = new NullExp(loc);
else
e = new AddrExp(loc, e);
e = new AddrExp(loc, e);
}
else
{
Expand Down
8 changes: 1 addition & 7 deletions src/mtype.c
Expand Up @@ -4120,13 +4120,7 @@ Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident, int
e->error("%s is not an expression", e->toChars());
return new ErrorExp();
}
if (size(e->loc) == 0)
e = new NullExp(e->loc, next->pointerTo());
else
{
e = new IndexExp(e->loc, e, new IntegerExp(0));
e = new AddrExp(e->loc, e);
}
e = e->castTo(sc, e->type->nextOf()->pointerTo());
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion test/runnable/xtest46.d
Expand Up @@ -6191,7 +6191,7 @@ void test161()
void test8819()
{
void[0] sa0 = (void[0]).init;
assert(sa0.ptr is null);
assert(sa0.ptr !is null); // 7175 - ptr should not be null

void[1] sa1 = (void[1]).init;
assert((cast(ubyte*)sa1.ptr)[0] == 0);
Expand Down

0 comments on commit 36c9b64

Please sign in to comment.