| author | |
| committer | |
| log | 621629e20d7114d09761b49d8fb2bba203aadd1a |
| tree | 4fb02a16d8d16ce54aad4593d23ba515e02a9442 |
| parent | f5e7d2d00c0bfdbdf95c57b8b5528f945fcf00c2 |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 17 insertions(+), 1 deletions(-)
src-self-hosted/translate_c.zig+4-1| ... | @@ -1792,7 +1792,10 @@ fn transDoWhileLoop( | ... | @@ -1792,7 +1792,10 @@ fn transDoWhileLoop( |
| 1792 | // zig: b; | 1792 | // zig: b; |
| 1793 | // zig: if (!cond) break; | 1793 | // zig: if (!cond) break; |
| 1794 | // zig: } | 1794 | // zig: } |
| 1795 | break :blk (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?; | 1795 | const body = (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?; |
| 1796 | // if this is used as an expression in Zig it needs to be immediately followed by a semicolon | ||
| 1797 | _ = try appendToken(rp.c, .Semicolon, ";"); | ||
| 1798 | break :blk body; | ||
| 1796 | } else blk: { | 1799 | } else blk: { |
| 1797 | // the C statement is without a block, so we need to create a block to contain it. | 1800 | // the C statement is without a block, so we need to create a block to contain it. |
| 1798 | // c: do | 1801 | // c: do |
test/translate_c.zig+13| ... | @@ -2185,4 +2185,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { | ... | @@ -2185,4 +2185,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { |
| 2185 | , &[_][]const u8{ | 2185 | , &[_][]const u8{ |
| 2186 | \\pub const FOO = if (a) b else c; | 2186 | \\pub const FOO = if (a) b else c; |
| 2187 | }); | 2187 | }); |
| 2188 | |||
| 2189 | cases.add("do while as expr", | ||
| 2190 | \\static void foo(void) { | ||
| 2191 | \\ if (1) | ||
| 2192 | \\ do {} while (0); | ||
| 2193 | \\} | ||
| 2194 | , &[_][]const u8{ | ||
| 2195 | \\pub fn foo() void { | ||
| 2196 | \\ if (1 != 0) while (true) { | ||
| 2197 | \\ if (!(0 != 0)) break; | ||
| 2198 | \\ }; | ||
| 2199 | \\} | ||
| 2200 | }); | ||
| 2188 | } | 2201 | } |