Commit 4fc944dde8
Changed files (4)
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) {
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 <stdint.h>
#if !defined(__UINTPTR_MAX__)
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" {
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));
\\ };
\\}
});