Skip to content

Commit f2dccc5

Browse files
committed
Renames and fixes
1 parent daac8a7 commit f2dccc5

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,8 +1703,8 @@ bool Converter::VisitCallExpr(clang::CallExpr *expr) {
17031703
computed_expr_type_ = ComputedExprType::FreshValue;
17041704
return false;
17051705
}
1706-
computed_expr_type_ = ComputedExprType::FreshValue;
17071706
StrCat(std::format("{}", ToString(expr->getArg(0))));
1707+
computed_expr_type_ = ComputedExprType::FreshValue;
17081708
return false;
17091709
}
17101710

@@ -3350,9 +3350,7 @@ bool Converter::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
33503350
// Take suppress before recursing into the child.
33513351
bool suppress = PushSuppressIteratorClone::take(*this);
33523352
Convert(expr->getArg(0));
3353-
bool clone =
3354-
ctor->isCopyConstructor() ||
3355-
(ctor->isMoveConstructor() && IsUserDefinedDecl(ctor->getParent()));
3353+
bool clone = ctor->isCopyConstructor() || IsDefaultedMoveConstructor(ctor);
33563354
if (clone && !suppress && !TypeIsCopyable(expr->getType())) {
33573355
StrCat(".clone()");
33583356
}

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,11 @@ bool IsUserDefinedCopyOrMoveConstructor(const clang::CXXConstructorDecl *ctor) {
269269
}
270270

271271
bool IsDefaultedMoveConstructor(const clang::CXXConstructorDecl *ctor) {
272-
return ctor->isMoveConstructor() &&
273-
!IsUserDefinedCopyOrMoveConstructor(ctor) &&
272+
return ctor->isMoveConstructor() && !ctor->isUserProvided() &&
274273
IsUserDefinedDecl(ctor->getParent());
275274
}
276275

277-
bool IsCopyOrMoveSpecialMember(const clang::CXXMethodDecl *method) {
276+
bool IsCopyOrMoveAssignmentOrCtor(const clang::CXXMethodDecl *method) {
278277
if (const auto *ctor = clang::dyn_cast<clang::CXXConstructorDecl>(method)) {
279278
return ctor->isCopyOrMoveConstructor();
280279
}
@@ -349,7 +348,7 @@ bool IsConvertibleCXXRecordDecl(const clang::CXXRecordDecl *decl) {
349348
return method->getDefinition() || method->isPureVirtual() ||
350349
method->getTemplateInstantiationPattern() ||
351350
method->getDescribedFunctionTemplate() ||
352-
IsCopyOrMoveSpecialMember(method);
351+
IsCopyOrMoveAssignmentOrCtor(method);
353352
});
354353
}
355354

‎cpp2rust/converter/converter_lib.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool IsUserDefinedCopyOrMoveConstructor(const clang::CXXConstructorDecl *ctor);
6969

7070
bool IsDefaultedMoveConstructor(const clang::CXXConstructorDecl *ctor);
7171

72-
bool IsCopyOrMoveSpecialMember(const clang::CXXMethodDecl *method);
72+
bool IsCopyOrMoveAssignmentOrCtor(const clang::CXXMethodDecl *method);
7373

7474
clang::CXXConstructorDecl *
7575
GetUserDefinedCopyConstructor(const clang::RecordDecl *decl);

‎cpp2rust/converter/models/converter_refcount.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,10 @@ bool ConverterRefCount::VisitCXXConstructExpr(clang::CXXConstructExpr *expr) {
18731873
return false;
18741874
}
18751875

1876+
// Default move is translated using a bitwise .clone() implementation.
1877+
// Bitwise clone is only satisfied by default copy constructor. If the copy
1878+
// constructor is user defined, then default move calls copy constructor,
1879+
// which is wrong.
18761880
if (IsDefaultedMoveConstructor(ctor) &&
18771881
!HasDefaultedCopyConstructor(ctor->getParent())) {
18781882
llvm::report_fatal_error("defaulted move constructor without a fieldwise "

0 commit comments

Comments
 (0)