Skip to content

Commit 921538d

Browse files
committed
Return 0 when main falls off its end
1 parent f467a98 commit 921538d

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,12 @@ void Converter::ConvertFunctionBody(clang::FunctionDecl *decl) {
429429
return;
430430
}
431431
auto compound = clang::dyn_cast<clang::CompoundStmt>(decl->getBody());
432+
if (decl->isMain() && compound &&
433+
(compound->body_empty() ||
434+
!clang::isa<clang::ReturnStmt>(compound->body_back()))) {
435+
StrCat("0");
436+
return;
437+
}
432438
if (!compound || compound->body_empty()) {
433439
return;
434440
}

‎tests/unit/empty_main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
int main(int, char **) { return 0; }
1+
int main(int, char **) {}

0 commit comments

Comments
 (0)