Skip to content

Commit

Permalink
Allow empty bracket for primitive initializer
Browse files Browse the repository at this point in the history
C2X
  • Loading branch information
tyfkda committed Dec 17, 2024
1 parent 60b1b05 commit 39331eb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/cc/frontend/initializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,17 @@ Initializer *flatten_initializer(Type *type, Initializer *init) {
} else {
switch (init->kind) {
case IK_MULTI:
if (init->multi->len == 0) {
init->kind = IK_SINGLE;
#ifndef __NO_FLONUM
if (is_flonum(type)) {
init->single = new_expr_flolit(type, init->token, 0);
break;
}
#endif
init->single = new_expr_fixlit(type, init->token, 0);
break;
}
if (init->multi->len != 1 || ((Initializer*)init->multi->data[0])->kind != IK_SINGLE) {
parse_error(PE_NOFATAL, init->token, "Requires scaler");
break;
Expand Down
3 changes: 3 additions & 0 deletions tests/valtest.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,9 @@ TEST(all) {
{
char buf[3] = {};
EXPECT("char array with empty initializer", 0, buf[0]);

int z = {};
EXPECT("primitive with empty initializer", 0, z);
}
{
struct {int x; int y;} s = {3};
Expand Down

0 comments on commit 39331eb

Please sign in to comment.