diff --git a/src/translate_c.zig b/src/translate_c.zig index 219635859c..7cc843e17c 100644 --- a/src/translate_c.zig +++ b/src/translate_c.zig @@ -5651,13 +5651,14 @@ const ParseError = Error || error{ParseError}; fn parseCExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node { // TODO parseCAssignExpr here - const node = try parseCCondExpr(c, m, scope); + var block_scope = try Scope.Block.init(c, scope, true); + defer block_scope.deinit(); + + const node = try parseCCondExpr(c, m, &block_scope.base); if (m.next().? != .Comma) { m.i -= 1; return node; } - var block_scope = try Scope.Block.init(c, scope, true); - defer block_scope.deinit(); var last = node; while (true) { diff --git a/test/behavior/translate_c_macros.h b/test/behavior/translate_c_macros.h index 439577fecc..5d4cf3473d 100644 --- a/test/behavior/translate_c_macros.h +++ b/test/behavior/translate_c_macros.h @@ -40,6 +40,7 @@ union U { #define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val)) #define NESTED_COMMA_OPERATOR (1, (2, 3)) +#define NESTED_COMMA_OPERATOR_LHS (1, 2), 3 #include #if !defined(__UINTPTR_MAX__) diff --git a/test/behavior/translate_c_macros.zig b/test/behavior/translate_c_macros.zig index 04d217f488..deda45df91 100644 --- a/test/behavior/translate_c_macros.zig +++ b/test/behavior/translate_c_macros.zig @@ -100,6 +100,7 @@ test "nested comma operator" { if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR); + try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS); } test "cast functions" { diff --git a/test/translate_c.zig b/test/translate_c.zig index d6b6bcbbba..81d1308c95 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -499,20 +499,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int baz(int x, int y) { return 0; } \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2)) , &[_][]const u8{ - \\pub const foo = blk: { + \\pub const foo = blk_1: { \\ _ = @TypeOf(foo); - \\ break :blk bar; + \\ break :blk_1 bar; \\}; , \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { - \\ return blk: { + \\ return blk_1: { \\ _ = &x; \\ _ = @as(c_int, 3); \\ _ = @as(c_int, 4) == @as(c_int, 4); \\ _ = @as(c_int, 5) * @as(c_int, 6); \\ _ = baz(@as(c_int, 1), @as(c_int, 2)); \\ _ = @as(c_int, 2) % @as(c_int, 2); - \\ break :blk baz(@as(c_int, 1), @as(c_int, 2)); + \\ break :blk_1 baz(@as(c_int, 1), @as(c_int, 2)); \\ }; \\} });