diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 9bee3eb9..15a10b5a 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -1263,6 +1263,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer( ConvertFunctionPointerType( fn_decl->getType()->getAs()), Mapper::MapFunctionName(fn_decl))); + computed_expr_type_ = ComputedExprType::FreshPointer; } void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) { @@ -1322,7 +1323,7 @@ bool ConverterRefCount::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) { if (expr->getTypeAsWritten()->isVoidType()) { PushExprKind push(*this, ExprKind::Void); Convert(expr->getSubExpr()); - if (!TypeIsCopyable(expr->getSubExpr()->getType())) { + if (!TypeIsCopyable(expr->getSubExpr()->getType()) && !isFresh()) { StrCat(".clone()"); } return false; diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 77724cab..0933260f 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -104,11 +104,11 @@ fn main_0() -> i32 { })); assert!(((*err.borrow()) == 7)); assert!(((*chosen.borrow()) == 123)); - bump_and_return_4.clone(); + bump_and_return_4; assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); - (FnPtr:: i32>::new(bump_and_return_4)).clone(); + (FnPtr:: i32>::new(bump_and_return_4)); assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); - ((FnPtr:: i32>::new(bump_and_return_4)).cast:: i32>(None)).clone(); + ((FnPtr:: i32>::new(bump_and_return_4)).cast:: i32>(None)); assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2)); let storage: Value = Rc::new(RefCell::new(11)); let p: Value> = Rc::new(RefCell::new((storage.as_pointer())));