Skip to content

Commit 0b2a215

Browse files
committed
Add mutability to address of ternary operand
1 parent ed9ff32 commit 0b2a215

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2954,10 +2954,11 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) {
29542954
ConvertCondition(expr->getCond());
29552955
bool branch_is_addr =
29562956
expr->isLValue() && !isRValue() && !expr->getType()->isFunctionType();
2957+
bool branch_is_mut = curr_init_type_.empty() || IsMut(curr_init_type_.back());
29572958
{
29582959
PushBrace then_brace(*this);
29592960
if (branch_is_addr) {
2960-
StrCat(token::kRef, keyword_mut_);
2961+
StrCat(token::kRef, branch_is_mut ? keyword_mut_ : "");
29612962
}
29622963
PushExplicitAutoref no_autoref(*this, branch_is_addr ? std::nullopt
29632964
: autoref_mut_);
@@ -2969,7 +2970,7 @@ bool Converter::VisitConditionalOperator(clang::ConditionalOperator *expr) {
29692970
{
29702971
PushBrace else_brace(*this);
29712972
if (branch_is_addr) {
2972-
StrCat(token::kRef, keyword_mut_);
2973+
StrCat(token::kRef, branch_is_mut ? keyword_mut_ : "");
29732974
}
29742975
PushExplicitAutoref no_autoref(*this, branch_is_addr ? std::nullopt
29752976
: autoref_mut_);

0 commit comments

Comments
 (0)