| author | |
| committer | |
| log | 4fc944dde813638410850515b0d1b156e5b6e920 |
| tree | 57af939346f904b0da8348d10de6666a1e948022 |
| parent | d773b7e71f8d9fd3d69c1f90cec9a941fc9f9a12 |
Closes #132394 files changed, 10 insertions(+), 7 deletions(-)
src/translate_c.zig+4-3| ... | ... | @@ -5651,13 +5651,14 @@ const ParseError = Error || error{ParseError}; |
| 5651 | 5651 | |
| 5652 | 5652 | fn parseCExpr(c: *Context, m: *MacroCtx, scope: *Scope) ParseError!Node { |
| 5653 | 5653 | // TODO parseCAssignExpr here |
| 5654 | const node = try parseCCondExpr(c, m, scope); | |
| 5654 | var block_scope = try Scope.Block.init(c, scope, true); | |
| 5655 | defer block_scope.deinit(); | |
| 5656 | ||
| 5657 | const node = try parseCCondExpr(c, m, &block_scope.base); | |
| 5655 | 5658 | if (m.next().? != .Comma) { |
| 5656 | 5659 | m.i -= 1; |
| 5657 | 5660 | return node; |
| 5658 | 5661 | } |
| 5659 | var block_scope = try Scope.Block.init(c, scope, true); | |
| 5660 | defer block_scope.deinit(); | |
| 5661 | 5662 | |
| 5662 | 5663 | var last = node; |
| 5663 | 5664 | while (true) { |
test/behavior/translate_c_macros.h+1| ... | ... | @@ -40,6 +40,7 @@ union U { |
| 40 | 40 | #define CAST_OR_CALL_WITH_PARENS(type_or_fn, val) ((type_or_fn)(val)) |
| 41 | 41 | |
| 42 | 42 | #define NESTED_COMMA_OPERATOR (1, (2, 3)) |
| 43 | #define NESTED_COMMA_OPERATOR_LHS (1, 2), 3 | |
| 43 | 44 | |
| 44 | 45 | #include <stdint.h> |
| 45 | 46 | #if !defined(__UINTPTR_MAX__) |
test/behavior/translate_c_macros.zig+1| ... | ... | @@ -100,6 +100,7 @@ test "nested comma operator" { |
| 100 | 100 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO |
| 101 | 101 | |
| 102 | 102 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR); |
| 103 | try expectEqual(@as(c_int, 3), h.NESTED_COMMA_OPERATOR_LHS); | |
| 103 | 104 | } |
| 104 | 105 | |
| 105 | 106 | test "cast functions" { |
test/translate_c.zig+4-4| ... | ... | @@ -499,20 +499,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 499 | 499 | \\int baz(int x, int y) { return 0; } |
| 500 | 500 | \\#define bar(x) (&x, +3, 4 == 4, 5 * 6, baz(1, 2), 2 % 2, baz(1,2)) |
| 501 | 501 | , &[_][]const u8{ |
| 502 | \\pub const foo = blk: { | |
| 502 | \\pub const foo = blk_1: { | |
| 503 | 503 | \\ _ = @TypeOf(foo); |
| 504 | \\ break :blk bar; | |
| 504 | \\ break :blk_1 bar; | |
| 505 | 505 | \\}; |
| 506 | 506 | , |
| 507 | 507 | \\pub inline fn bar(x: anytype) @TypeOf(baz(@as(c_int, 1), @as(c_int, 2))) { |
| 508 | \\ return blk: { | |
| 508 | \\ return blk_1: { | |
| 509 | 509 | \\ _ = &x; |
| 510 | 510 | \\ _ = @as(c_int, 3); |
| 511 | 511 | \\ _ = @as(c_int, 4) == @as(c_int, 4); |
| 512 | 512 | \\ _ = @as(c_int, 5) * @as(c_int, 6); |
| 513 | 513 | \\ _ = baz(@as(c_int, 1), @as(c_int, 2)); |
| 514 | 514 | \\ _ = @as(c_int, 2) % @as(c_int, 2); |
| 515 | \\ break :blk baz(@as(c_int, 1), @as(c_int, 2)); | |
| 515 | \\ break :blk_1 baz(@as(c_int, 1), @as(c_int, 2)); | |
| 516 | 516 | \\ }; |
| 517 | 517 | \\} |
| 518 | 518 | }); |