Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cpp2rust/converter/models/converter_refcount.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ void ConverterRefCount::ConvertFunctionToFunctionPointer(
ConvertFunctionPointerType(
fn_decl->getType()->getAs<clang::FunctionProtoType>()),
Mapper::MapFunctionName(fn_decl)));
computed_expr_type_ = ComputedExprType::FreshPointer;
}

void ConverterRefCount::ConvertEqualsNullPtr(clang::Expr *expr) {
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/out/refcount/void_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<fn() -> i32>::new(bump_and_return_4)).clone();
(FnPtr::<fn() -> i32>::new(bump_and_return_4));
assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2));
((FnPtr::<fn() -> i32>::new(bump_and_return_4)).cast::<fn() -> i32>(None)).clone();
((FnPtr::<fn() -> i32>::new(bump_and_return_4)).cast::<fn() -> i32>(None));
assert!(((*side_effect_counter_3.with(Value::clone).borrow()) == 2));
let storage: Value<i32> = Rc::new(RefCell::new(11));
let p: Value<Ptr<i32>> = Rc::new(RefCell::new((storage.as_pointer())));
Expand Down
Loading