Skip to content

Commit

Permalink
Relax FAM to use for array
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Dec 13, 2024
1 parent 7b41972 commit 1b1202e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 0 additions & 6 deletions src/cc/frontend/parser_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,6 @@ static Type *parse_direct_declarator_suffix(Type *type) {
if (basetype->qualifier & TQ_CONST)
type->qualifier |= TQ_CONST;
}

// Flexible array struct not allowd.
if (basetype->kind == TY_STRUCT) {
if (basetype->struct_.info != NULL && basetype->struct_.info->is_flexible)
parse_error(PE_NOFATAL, tok, "using flexible array as an array not allowed.");
}
} else if (match(TK_LPAR)) {
bool vaargs;
Vector *param_vars = parse_funparams(&vaargs);
Expand Down
5 changes: 3 additions & 2 deletions tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ test_struct() {
compile_error 'union for struct' 'struct Foo{int x;}; int main(){ union Foo foo; (void)foo; }'
compile_error 'no member name' 'struct Foo{union{int anon;}; int;}; int main(){}'
compile_error 'FAM must be last' 'struct Foo{int a; int b[]; int y;}; int main(){}'
compile_error 'FAM cannot array' 'struct Foo{int a; int b[];}; struct Foo x[5]; int main(){}'
compile_error 'FAM cannot struct' 'struct Foo{int a; int b[];}; struct Bar {struct Foo foo; int x;}; int main(){}'
try_direct 'FAM array' 20 'struct Foo{int a; int b[];}; struct Foo x[5]; int main(){return sizeof(x);}'
compile_error 'FAM not last in struct' 'struct Foo{int a; int b[];}; struct Bar {struct Foo foo; int x;}; int main(){}'
try_direct 'FAM at last in struct' 8 'struct Foo{int a; int b[];}; struct Bar {int x; struct Foo foo;}; int main(){return sizeof(struct Bar);}'

end_test_suite
}
Expand Down

0 comments on commit 1b1202e

Please sign in to comment.