Skip to content

Commit 1043112

Browse files
committed
Make HasCallableCopyCtor recursive
1 parent d6fa5c5 commit 1043112

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -502,28 +502,17 @@ GetUserDefinedCopyConstructor(const clang::RecordDecl *decl) {
502502
return nullptr;
503503
}
504504

505-
static bool FieldsHaveCallableCopyConstructors(const clang::RecordDecl *decl) {
506-
auto &ctx = decl->getASTContext();
507-
return std::ranges::all_of(decl->fields(), [&](const clang::FieldDecl *f) {
508-
auto *record = ctx.getBaseElementType(f->getType())->getAsCXXRecordDecl();
509-
return !record || !IsUserDefinedDecl(record) ||
510-
HasCallableCopyConstructor(record);
511-
});
512-
}
513-
514505
bool HasDefaultedCopyConstructor(const clang::RecordDecl *decl) {
515506
auto *cxx = clang::dyn_cast<clang::CXXRecordDecl>(decl);
516507
if (!cxx) {
517508
return true;
518509
}
519510
for (const auto *ctor : cxx->ctors()) {
520-
if (ctor->isCopyConstructor()) {
521-
return !ctor->isUserProvided() && !ctor->isDeleted() &&
522-
FieldsHaveCallableCopyConstructors(cxx);
511+
if (ctor->isCopyConstructor() && ctor->isUserProvided()) {
512+
return false;
523513
}
524514
}
525-
return !cxx->defaultedCopyConstructorIsDeleted() &&
526-
FieldsHaveCallableCopyConstructors(cxx);
515+
return HasCallableCopyConstructor(cxx);
527516
}
528517

529518
bool RecordHasOnlyReferenceFields(const clang::RecordDecl *decl) {
@@ -553,16 +542,21 @@ bool HasCallableCopyConstructor(const clang::RecordDecl *decl) {
553542
if (!cxx) {
554543
return true;
555544
}
556-
if (!cxx->hasUserDeclaredCopyConstructor()) {
557-
return HasDefaultedCopyConstructor(cxx);
545+
if (cxx->hasUserDeclaredCopyConstructor()) {
546+
return std::ranges::any_of(cxx->ctors(), [](const auto *ctor) {
547+
return ctor->isCopyConstructor() && !ctor->isDeleted() &&
548+
ctor->getDefinition();
549+
});
558550
}
559-
for (const auto *ctor : cxx->ctors()) {
560-
if (ctor->isCopyConstructor() && !ctor->isDeleted() &&
561-
ctor->getDefinition()) {
562-
return true;
563-
}
551+
if (cxx->defaultedCopyConstructorIsDeleted()) {
552+
return false;
564553
}
565-
return false;
554+
auto &ctx = cxx->getASTContext();
555+
return std::ranges::all_of(cxx->fields(), [&](const clang::FieldDecl *f) {
556+
auto *record = ctx.getBaseElementType(f->getType())->getAsCXXRecordDecl();
557+
return !record || !IsUserDefinedDecl(record) ||
558+
HasCallableCopyConstructor(record);
559+
});
566560
}
567561

568562
bool IsRValueConvertingConstructor(const clang::CXXConstructorDecl *ctor) {

0 commit comments

Comments
 (0)