translate-c-2 fix assertion failure rendering do while
parent
f5e7d2d00c
commit
621629e20d
|
@ -1792,7 +1792,10 @@ fn transDoWhileLoop(
|
|||
// zig: b;
|
||||
// zig: if (!cond) break;
|
||||
// zig: }
|
||||
break :blk (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?;
|
||||
const body = (try transStmt(rp, &loop_scope, ZigClangDoStmt_getBody(stmt), .unused, .r_value)).cast(ast.Node.Block).?;
|
||||
// if this is used as an expression in Zig it needs to be immediately followed by a semicolon
|
||||
_ = try appendToken(rp.c, .Semicolon, ";");
|
||||
break :blk body;
|
||||
} else blk: {
|
||||
// the C statement is without a block, so we need to create a block to contain it.
|
||||
// c: do
|
||||
|
|
|
@ -2185,4 +2185,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
|
|||
, &[_][]const u8{
|
||||
\\pub const FOO = if (a) b else c;
|
||||
});
|
||||
|
||||
cases.add("do while as expr",
|
||||
\\static void foo(void) {
|
||||
\\ if (1)
|
||||
\\ do {} while (0);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
\\pub fn foo() void {
|
||||
\\ if (1 != 0) while (true) {
|
||||
\\ if (!(0 != 0)) break;
|
||||
\\ };
|
||||
\\}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue