Skip to content

Commit d27a391

Browse files
committed
Conditions produce rvalues
1 parent d56970d commit d27a391

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

cpp2rust/converter/converter.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,8 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) {
918918

919919
void Converter::ConvertCondition(clang::Expr *cond) {
920920
if (!cond->getType()->isBooleanType()) {
921-
StrCat(ConvertRValue(CreateConversionToBool(cond, ctx_)));
921+
PushExprKind push(*this, ExprKind::RValue);
922+
Convert(CreateConversionToBool(cond, ctx_));
922923
return;
923924
}
924925
Convert(cond);
@@ -1849,13 +1850,13 @@ bool Converter::VisitBinaryOperator(clang::BinaryOperator *expr) {
18491850
void Converter::ConvertGenericBinaryOperator(clang::BinaryOperator *expr) {
18501851
StrCat(token::kOpenParen);
18511852
StrCat(token::kOpenParen);
1852-
StrCat(ConvertRValue(expr->getLHS()));
1853+
Convert(expr->getLHS());
18531854
StrCat(token::kCloseParen);
18541855

18551856
StrCat(expr->getOpcodeStr());
18561857

18571858
StrCat(token::kOpenParen);
1858-
StrCat(ConvertRValue(expr->getRHS()));
1859+
Convert(expr->getRHS());
18591860
StrCat(token::kCloseParen);
18601861
StrCat(token::kCloseParen);
18611862
}
@@ -2893,12 +2894,12 @@ void Converter::ConvertAssignment(clang::Expr *lhs, clang::Expr *rhs,
28932894
curr_init_type_.pop();
28942895
auto rhs_as_string = ConvertFreshRValue(rhs);
28952896

2896-
if (isRValue()) {
2897+
if (!isVoid()) {
28972898
StrCat(token::kOpenCurlyBracket);
28982899
}
28992900

29002901
StrCat(lhs_as_string, assign_operator, rhs_as_string);
2901-
if (isRValue()) {
2902+
if (!isVoid()) {
29022903
StrCat(token::kSemiColon, ConvertRValue(lhs), token::kCloseCurlyBracket);
29032904
}
29042905
}

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,8 +1622,11 @@ void ConverterRefCount::ConvertGenericBinaryOperator(
16221622
return;
16231623
}
16241624

1625-
StrCat(token::kOpenParen, ConvertRValue(lhs), opcode, ConvertRValue(rhs),
1626-
token::kCloseParen);
1625+
StrCat(token::kOpenParen);
1626+
Convert(lhs);
1627+
StrCat(opcode);
1628+
Convert(rhs);
1629+
StrCat(token::kCloseParen);
16271630
}
16281631

16291632
void ConverterRefCount::ConvertUniquePtrDeref(

0 commit comments

Comments
 (0)