Add flexible array member

This commit is contained in:
Rui Ueyama 2020-09-20 16:11:55 +09:00
parent 3d216e3e06
commit 824543bb2f
2 changed files with 8 additions and 0 deletions

View File

@ -1706,6 +1706,12 @@ static void struct_members(Token **rest, Token *tok, Type *ty) {
}
}
// If the last element is an array of incomplete type, it's
// called a "flexible array member". It should behave as if
// if were a zero-sized array.
if (cur != &head && cur->ty->kind == TY_ARRAY && cur->ty->array_len < 0)
cur->ty = array_of(cur->ty->base, 0);
*rest = tok->next;
ty->members = head.next;
}

View File

@ -34,6 +34,8 @@ int main() {
ASSERT(8, sizeof(int(*)[10]));
ASSERT(8, sizeof(int(*)[][10]));
ASSERT(4, sizeof(struct { int x, y[]; }));
printf("OK\n");
return 0;
}