translate-c supports returning void

This commit is contained in:
Andrew Kelley 2017-11-25 00:25:47 -05:00
parent cd36baf530
commit 18eb3c5f90
2 changed files with 11 additions and 2 deletions

View File

@ -937,8 +937,7 @@ static AstNode *trans_compound_stmt(Context *c, AstNode *parent, CompoundStmt *s
static AstNode *trans_return_stmt(Context *c, AstNode *block, ReturnStmt *stmt) {
Expr *value_expr = stmt->getRetValue();
if (value_expr == nullptr) {
emit_warning(c, stmt->getLocStart(), "TODO handle C return void");
return nullptr;
return trans_create_node(c, NodeTypeReturnExpr);
} else {
AstNode *return_node = trans_create_node(c, NodeTypeReturnExpr);
return_node->data.return_expr.expr = trans_expr(c, true, block, value_expr, TransRValue);

View File

@ -939,6 +939,16 @@ pub fn addCases(cases: &tests.TranslateCContext) {
\\ return c"bar";
\\}
);
cases.add("return void",
\\void foo(void) {
\\ return;
\\}
,
\\pub fn foo() {
\\ return;
\\}
);
}