Skip to content

Commit 614e78e

Browse files
committed
Fix nested switches
1 parent 0c143fe commit 614e78e

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ bool Converter::VisitCXXForRangeStmtIndexBased(clang::CXXForRangeStmt *stmt,
11371137

11381138
bool Converter::VisitBreakStmt([[maybe_unused]] clang::BreakStmt *stmt) {
11391139
StrCat(keyword::kBreak);
1140-
if (break_with_explicit_label_) {
1140+
if (switch_depth_ > 0) {
11411141
StrCat("'switch");
11421142
}
11431143
return false;
@@ -2703,7 +2703,7 @@ bool Converter::VisitSwitchStmt(clang::SwitchStmt *stmt) {
27032703
StrCat("match __match_cond");
27042704
StrCat("{");
27052705

2706-
break_with_explicit_label_ = true;
2706+
++switch_depth_;
27072707

27082708
clang::SwitchCase *default_case = nullptr;
27092709
for (auto *sc : GetTopLevelSwitchCases(stmt)) {
@@ -2729,7 +2729,7 @@ bool Converter::VisitSwitchStmt(clang::SwitchStmt *stmt) {
27292729
StrCat(R"( _ => {})");
27302730
}
27312731

2732-
break_with_explicit_label_ = false;
2732+
--switch_depth_;
27332733

27342734
StrCat("}");
27352735
StrCat("}");

cpp2rust/converter/converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class Converter : public clang::RecursiveASTVisitor<Converter> {
463463
clang::ASTContext &ctx_;
464464
clang::FunctionDecl *curr_function_ = nullptr;
465465
bool in_function_formals_ = false;
466-
bool break_with_explicit_label_ = false;
466+
int switch_depth_ = 0;
467467
std::stack<clang::Expr *> curr_for_inc_;
468468
std::stack<clang::QualType> curr_init_type_;
469469

0 commit comments

Comments
 (0)