diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig index f2eaa369..83c46f33 100644 --- a/src/aro/Parser.zig +++ b/src/aro/Parser.zig @@ -3266,7 +3266,22 @@ fn complexInitializer(p: *Parser, init_ty: Type) Error!Result { } } + // Eat excess initializers + var extra_tok: ?TokenIndex = null; + while (p.eatToken(.comma)) |_| { + if (p.tok_ids[p.tok_i] == .r_brace) break; + extra_tok = p.tok_i; + const extra = try p.assignExpr(); + if (extra.empty(p)) { + try p.errTok(.expected_expr, p.tok_i); + p.skipTo(.r_brace); + return error.ParsingFailed; + } + } try p.expectClosing(l_brace, .r_brace); + if (extra_tok) |tok| { + try p.errTok(.excess_scalar_init, tok); + } const arr_init_node: Tree.Node = .{ .tag = .array_init_expr_two, diff --git a/test/cases/complex values.c b/test/cases/complex values.c index 60724410..7bc1d165 100644 --- a/test/cases/complex values.c +++ b/test/cases/complex values.c @@ -38,6 +38,12 @@ _Static_assert(1.0 / (_Complex double){__builtin_inf(), __builtin_nan("")} == 0. constexpr _Complex double product = (_Complex double){__builtin_inf(), __builtin_nan("") * 2.0}; _Static_assert(__builtin_isinf(__real__ product), ""); _Static_assert(__builtin_isnan(__imag__ product), ""); +_Complex double a = (_Complex double) {1.0, 2.0,}; +_Complex double b = (_Complex double) {1.0, 2.0,,,,,,}; +_Complex double c = (_Complex double) {1.0, 2.0,3.0}; + #define EXPECTED_ERRORS "complex values.c:24:17: error: static_assert expression is not an integral constant expression" \ + "complex values.c:42:49: error: expected expression" \ + "complex values.c:43:49: warning: excess elements in scalar initializer [-Wexcess-initializers]" \