Skip to content

Commit 6dd37dc

Browse files
committed
Only add clone on non-Copy types
1 parent a73306f commit 6dd37dc

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

cpp2rust/converter/converter_lib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,4 +814,9 @@ ConstCastType GetConstCastType(clang::QualType to, clang::QualType from) {
814814
}
815815
}
816816

817+
bool TypeIsCopyable(clang::QualType ty) {
818+
return ty->isIntegerType() || ty->isFunctionPointerType() ||
819+
ty->isFunctionType();
820+
}
821+
817822
} // namespace cpp2rust

cpp2rust/converter/converter_lib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,6 @@ enum class ConstCastType {
180180

181181
ConstCastType GetConstCastType(clang::QualType to, clang::QualType from);
182182

183+
bool TypeIsCopyable(clang::QualType ty);
184+
183185
} // namespace cpp2rust

cpp2rust/converter/models/converter_refcount.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,9 @@ bool ConverterRefCount::VisitExplicitCastExpr(clang::ExplicitCastExpr *expr) {
11301130
if (expr->getTypeAsWritten()->isVoidType()) {
11311131
PushExprKind push(*this, ExprKind::Void);
11321132
Convert(expr->getSubExpr());
1133+
if (!TypeIsCopyable(expr->getSubExpr()->getType())) {
1134+
StrCat(".clone()");
1135+
}
11331136
return false;
11341137
}
11351138
switch (expr->getStmtClass()) {

0 commit comments

Comments
 (0)