Skip to content

Commit f2483a7

Browse files
committed
Simplify destructor checks
1 parent 01c9e36 commit f2483a7

3 files changed

Lines changed: 5 additions & 33 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ bool Converter::RecordDerivesCopy(const clang::RecordDecl *decl) const {
678678

679679
bool Converter::RecordHasCopyableFields(const clang::RecordDecl *decl) {
680680
if (auto *cxx = clang::dyn_cast<clang::CXXRecordDecl>(decl);
681-
cxx && RecordNeedsDestruction(cxx)) {
681+
cxx && !cxx->hasTrivialDestructor()) {
682682
return false;
683683
}
684684
for (auto f : decl->fields()) {

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -589,39 +589,15 @@ const char *GetOverloadedOperator(const clang::FunctionDecl *decl) {
589589

590590
clang::CXXDestructorDecl *
591591
GetTranslatableDestructor(const clang::CXXRecordDecl *decl) {
592-
if (!decl->hasDefinition() || !IsUserDefinedDecl(decl) ||
593-
!decl->hasUserDeclaredDestructor()) {
592+
if (!IsUserDefinedDecl(decl)) {
594593
return nullptr;
595594
}
596595
auto *dtor = decl->getDestructor();
597-
if (!dtor || dtor->isImplicit() || !dtor->getDefinition() ||
598-
dtor->getDefinition()->isDefaulted()) {
596+
if (!dtor || dtor->isImplicit()) {
599597
return nullptr;
600598
}
601-
return dtor;
602-
}
603-
604-
bool TypeNeedsDestruction(clang::QualType type) {
605-
if (type->isArrayType()) {
606-
type = clang::QualType(type->getBaseElementTypeUnsafe(), 0);
607-
}
608-
auto *record = type->getAsCXXRecordDecl();
609-
return record && RecordNeedsDestruction(record);
610-
}
611-
612-
bool RecordNeedsDestruction(const clang::CXXRecordDecl *decl) {
613-
if (!decl->hasDefinition() || !IsUserDefinedDecl(decl)) {
614-
return false;
615-
}
616-
if (GetTranslatableDestructor(decl)) {
617-
return true;
618-
}
619-
for (const auto *field : decl->fields()) {
620-
if (TypeNeedsDestruction(field->getType())) {
621-
return true;
622-
}
623-
}
624-
return false;
599+
auto *definition = dtor->getDefinition();
600+
return definition && !definition->isDefaulted() ? dtor : nullptr;
625601
}
626602

627603
bool IsOverloadedComparisonOperator(const clang::CXXMethodDecl *decl) {

‎cpp2rust/converter/converter_lib.h‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ bool IsOverloadedComparisonOperator(const clang::CXXMethodDecl *decl);
122122
clang::CXXDestructorDecl *
123123
GetTranslatableDestructor(const clang::CXXRecordDecl *decl);
124124

125-
bool TypeNeedsDestruction(clang::QualType type);
126-
127-
bool RecordNeedsDestruction(const clang::CXXRecordDecl *decl);
128-
129125
clang::Expr *ToAddrOf(clang::ASTContext &ctx, clang::Expr *expr);
130126

131127
std::vector<clang::CXXRecordDecl *>

0 commit comments

Comments
 (0)