From 39331eb95234e43f55d1caebb99f3a4ca65ce15d Mon Sep 17 00:00:00 2001 From: tyfkda Date: Mon, 16 Dec 2024 06:34:18 +0900 Subject: [PATCH] Allow empty bracket for primitive initializer C2X --- src/cc/frontend/initializer.c | 11 +++++++++++ tests/valtest.c | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/cc/frontend/initializer.c b/src/cc/frontend/initializer.c index ba64fc9b4..ebef2c189 100644 --- a/src/cc/frontend/initializer.c +++ b/src/cc/frontend/initializer.c @@ -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; diff --git a/tests/valtest.c b/tests/valtest.c index 540fb13b7..2c0030240 100644 --- a/tests/valtest.c +++ b/tests/valtest.c @@ -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};