Skip to content

Commit bd23a47

Browse files
committed
Fix clash between match_cond variable and local variable
1 parent cee15a3 commit bd23a47

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,7 +3105,7 @@ bool Converter::ConvertSwitchCaseCondition(clang::SwitchCase *stmt) {
31053105
while (auto *sc = clang::dyn_cast<clang::SwitchCase>(cur)) {
31063106
if (auto *case_stmt = clang::dyn_cast<clang::CaseStmt>(sc)) {
31073107
if (!first) {
3108-
StrCat("|| v == ");
3108+
StrCat("|| __v == ");
31093109
}
31103110
Convert(case_stmt->getLHS());
31113111
}
@@ -3127,7 +3127,7 @@ void Converter::EmitSwitchArm(clang::CompoundStmt *body, clang::SwitchCase *sc,
31273127
if (is_default) {
31283128
StrCat("_ => {");
31293129
} else {
3130-
StrCat("v if v == ");
3130+
StrCat("__v if __v == ");
31313131
ConvertSwitchCaseCondition(sc);
31323132
}
31333133
for (auto *t : GetSwitchCaseBody(body, sc)) {

tests/unit/switch_basic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
int basic(int x) {
44
int r = 0;
5+
int v = 0; // this should not clash with the match_cond translated variable
56
switch (x) {
67
case 0:
78
r = 10;

0 commit comments

Comments
 (0)